Comments (2)
Thanks for finding this.
It does look hard to fix. typing.Protocol
before 3.11 clobbered __init__
, so if you inherit from it, that's the behavior you'll get. We should simply document it, unless someone comes up with a clever way to prevent this behavior.
from typing_extensions.
Another limitation: with typing_extensions.Protocol
, it is possible to create a protocol that extends typing_extensions.Buffer
:
>>> import typing_extensions as te
>>> class Q(te.Buffer, te.Protocol): pass
...
>>>
But if you have both typing.Protocol
and typing_extensions.Protocol
in the mro, it doesn't work:
>>> 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.Buffer
in our version of _PROTO_ALLOWLIST
, but it obviously doesn't exist in the typing
version of _PROTO_ALLOWLIST
:
typing_extensions/src/typing_extensions.py
Lines 493 to 500 in fd1f853
from typing_extensions.
Related Issues (20)
- Third-party tests failed on Sun May 12 2024 HOT 1
- Third-party tests failed on Mon May 13 2024 HOT 1
- Third-party tests failed on Tue May 14 2024
- Improving the security of typing-extensions HOT 8
- PEP-696 specialisation tests from CPython fail HOT 3
- PEP-696: `AttributeError: attribute '__default__' of 'typing.ParamSpec' objects is not writable` on Python 3.13 HOT 4
- ParamSpec `_set_default` called from `ParamSpec.__new__` raises Attribute Error HOT 2
- Add an `override` decorator to a .pyi file HOT 8
- Add `inspect.get_annotations` backport
- Add `typing.get_type_hints` backport HOT 1
- Pylint raises error saying "default" isn't valid for TypeVar HOT 2
- Third-party tests failed on Sat Jun 01 2024 HOT 2
- `TypeError` on nested `Annotated`s with `typing_extensions==4.12.0`
- Third-party tests failed on Sun Jun 02 2024 HOT 2
- 4.12.1: `pyupgrade --py38-plus` generated patch causes pytest fails HOT 9
- Third-party tests failed on Mon Jun 03 2024 HOT 1
- Third-party tests failed on Thu Jun 06 2024 HOT 1
- Weird conflict between typing-extensions 4.12.1, xarray, dirty_equals on Python 3.8 HOT 2
- 4.12.2 creates an import bug HOT 2
- Add `typing_extensions.TypeExpr` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typing_extensions.