nat.observability.mixin.type_introspection_mixin#
Classes#
Mixin class providing type introspection capabilities for generic classes. |
Module Contents#
- class TypeIntrospectionMixin#
Mixin class providing type introspection capabilities for generic classes.
This mixin extracts type information from generic class definitions, allowing classes to determine their InputT and OutputT types at runtime.
- _find_generic_types() tuple[type[Any], type[Any]] | None#
Recursively search through the inheritance hierarchy to find generic type parameters.
This method handles cases where a class inherits from a generic parent class, resolving the concrete types through the inheritance chain.
- Returns:
tuple[type[Any], type[Any]] | None: (input_type, output_type) if found, None otherwise
- _substitute_type_var(type_expr: Any, concrete_type: type) type[Any]#
Substitute TypeVar in a type expression with a concrete type.
- Args:
type_expr: The type expression potentially containing TypeVars concrete_type: The concrete type to substitute
- Returns:
The type expression with TypeVars substituted
- property input_type: type[Any]#
Get the input type of the class. The input type is determined by the generic parameters of the class.
For example, if a class is defined as
MyClass[list[int], str], theinput_typeislist[int].Returns#
- type[Any]
The input type specified in the generic parameters
Raises#
- ValueError
If the input type cannot be determined from the class definition
- property output_type: type[Any]#
Get the output type of the class. The output type is determined by the generic parameters of the class.
For example, if a class is defined as
MyClass[list[int], str], theoutput_typeisstr.Returns#
- type[Any]
The output type specified in the generic parameters
Raises#
- ValueError
If the output type cannot be determined from the class definition
- property input_class: type#
Get the python class of the input type. This is the class that can be used to check if a value is an instance of the input type. It removes any generic or annotation information from the input type.
For example, if the input type is
list[int], theinput_classislist.Returns#
- type
The python type of the input type
- property output_class: type#
Get the python class of the output type. This is the class that can be used to check if a value is an instance of the output type. It removes any generic or annotation information from the output type.
For example, if the output type is
list[int], theoutput_classislist.Returns#
- type
The python type of the output type