I'm trying to check whether an argument is an instance of the generic type specified in the class declaration. However Python does not seem to allow this.
T = TypeVar('T')
class MyTypeChecker(Generic[T]):
def is_right_type(self, x: Any):
return isinstance(x, T)
This gives the error 'T' is a type variable and only valid in type context
.