The documentation for typing.TypeVar gives these two examples: T = TypeVar('T') # Can be anything A = TypeVar('A', str, bytes) # Must be str or bytes
I was suprised to find out that the following does not work, exception says that TypeVar is not definable with only one constraint: A = TypeVar('A', type) # Must be a type, like class Foo, etc (rather than an instance of a type) The TypeVar source code explicitely forbids only one type constraint, what is the rationale behind this? For those who wonder, my function parameter expects a type rather than an instance of a type, and returns a type. -- Oliver My StackOverflow contributions My CodeProject articles My Github projects My SourceForget.net projects -- https://mail.python.org/mailman/listinfo/python-list