-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
typing_extensions.Protocol
and typing.Protocol
don't always play well together
#245
Comments
Thanks for finding this. It does look hard to fix. |
Another limitation: with >>> import typing_extensions as te
>>> class Q(te.Buffer, te.Protocol): pass
...
>>> But if you have both >>> import typing as t, typing_extensions as te
>>> class P(t.Protocol): pass
...
>>> class Q(P, te.Buffer, te.Protocol): pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\alexw\coding\typing_extensions\src\typing_extensions.py", line 632, in __new__
return abc.ABCMeta.__new__(mcls, name, bases, namespace, **kwargs)
File "C:\Users\alexw\.conda\envs\py38\lib\abc.py", line 85, in __new__
cls = super().__new__(mcls, name, bases, namespace, **kwargs)
File "C:\Users\alexw\.conda\envs\py38\lib\typing.py", line 1119, in __init_subclass__
raise TypeError('Protocols can only inherit from other'
TypeError: Protocols can only inherit from other protocols, got <class 'typing_extensions.Buffer'> This is because we have typing_extensions/src/typing_extensions.py Lines 493 to 500 in fd1f853
|
If you're just using
typing_extensions.Protocol
, we backport python/cpython#31628 from Python 3.11. That means you can do this (the__init__
method on a protocol is retained, and can be used in concrete subclasses of that protocol):But, if you have both
typing.Protocol
andtyping_extensions.Protocol
in the mro, it doesn't work. On Python 3.8 (and, I assume, 3.9/3.10), there's this behaviour currently:I've been looking at it, and I think this may not be fixable, unfortunately. Should we document that this is a known limitation?
The text was updated successfully, but these errors were encountered: