I have a generic base class and I want to be able to inspect the provided type for it. My approach was using typing.get_args
which works like so:
from typing import Generic, Tuple, TypeVarTuple, get_args
T = TypeVarTuple("T")
class Base(Generic[*T]):
values: Tuple[*T]
Example = Base[int, str]
print(get_args(Example)) # (<class 'int'>, <class 'str'>)
But when I'm inheriting the class, I'm getting an empty list of parameters like so:
class Example2(Base[int, str]):
pass
print(get_args(Example2)) # ()
What I actually need is to know what types are expected for the values
property. I might have the wrong approach but I've also tried to use typing.get_type_hints
which seems to just return Tuple[*T]
as the type.
So how can I get the typed parameters?
Edit: I need to know the types of the class, not the object.