-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is_generic_type
is True for a non-generic Protocol
#58
Comments
In some sense this is expected behavior. The term "generic" is overloaded, meaning both "this class can still be parameterized with type argument", and "this class has Consider this example: from typing import TypeVar, Generic
T = TypeVar('T')
class C(Generic[T]):
...
class D(C[int]):
...
is_generic_type(D) # True
D[int] # TypeError: <class '__main__.D'> is not a generic class So |
I must agree that this is confusing.
That However, Or in other words, probably the confusing this is that you can do:
and
That is quite wired thing of the In some way the originating PEP544 underlines that, as it says:
Hence it is a convenient shorthand when a TypeVar is used, not that every Protocol is Generic (again although it is implemented in that way that every Protocol is a Generic). I would feel better if Mhmm or at least something like a function |
FWIW I don't want to change the current behavior, because it would be back wards incompatible, but I think it is OK to add a second helper like |
is_generic_type
returns True for a non-generic Protocol:Tested on Python 3.8.2 and Python 3.6.10:
implementation of
is_generic_type
The text was updated successfully, but these errors were encountered: