schrodinger.utils.type_checking module¶
- schrodinger.utils.type_checking.enforce_types(**expected_types)¶
A decorator factory for runtime type validation of function/method arguments.
Each keyword argument maps a parameter name to its expected type. The type may be a single type or a union of types expressed with the
|operator (e.g.str | None,int | float).- Parameters:
expected_types – Mapping of parameter name to expected type or union of types.
- Raises:
TypeError – If a validated argument’s type does not match the expectation. The error message includes the function name, parameter name, expected type, and actual type.
Usage:
# Single type @enforce_types(tristate=bool) def set_tristate(self, tristate: bool): ... # Union type — accepts Icon instance or None @enforce_types(icon=Icon | None) def set_indicator_icon(self, icon: Icon | None): ... # Multiple parameters @enforce_types(name=str, count=int | None) def configure(self, name: str, count: int | None = None): ...