I am having a hard time using python typing annotations when dealing with generics and compound types
Consider the following class:
import typing as ty
T = ty.TypeVar("T")
CT = tuple[bool, T, str]
class MyClass(ty.Generic[T]):
internal1: tuple[bool, T, str]
internal2: CT[T]
internal3: CT[float]
class DerivedMyClass(MyClass[float]):
pass
print(ty.get_type_hints(MyClass))
print(ty.get_type_hints(DerivedMyClass))
where the type of internal
1, 2, 3 is actually a much more lengthy type annotation. The output is:
{
'internal1': tuple[bool, ~T, str],
'internal2': tuple[bool, ~T, str],
'internal3': tuple[bool, float, str]
}
{
'internal1': tuple[bool, ~T, str],
'internal2': tuple[bool, ~T, str],
'internal3': tuple[bool, float, str]
}
Is there a way to make CT
aware of the type in the derived class?