-
-
Notifications
You must be signed in to change notification settings - Fork 117
Cannot parameterise typing_extensions.Protocol
with a ParamSpec
or TypeVarTuple
on py310+
#181
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
Comments
My guess is that this change might be the culprit, but haven't checked that at all: https://github.com/python/typing_extensions/pull/137/files#r1164017024 |
Minimal repro: >>> from typing_extensions import Protocol, ParamSpec
>>> P = ParamSpec("P")
>>> class Foo(Protocol[P]): ...
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\alexw\AppData\Local\Programs\Python\Python311\Lib\typing.py", line 344, in inner
return func(*args, **kwds)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\alexw\coding\typing_extensions\src\typing_extensions.py", line 672, in __class_getitem__
raise TypeError(
TypeError: Parameters to Protocol[...] must all be type variables. Parameter 1 is ~P Works fine on |
Interestingly, the bug only reproduces if you use Python >=3.10 (i.e., it has to be a version of Python where |
Seems like the fundamental issue is that:
|
typing_extensions.Protocol
with a ParamSpec
typing_extensions.Protocol
with a ParamSpec
typing_extensions.Protocol
with a ParamSpec
on py310+
Not that anybody asked, but the bug also means that you can't parameterise a >>> from typing_extensions import *
>>> Ts = TypeVarTuple("Ts")
>>> class Foo(Protocol[*Ts]): ...
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\alexw\AppData\Local\Programs\Python\Python311\Lib\typing.py", line 344, in inner
return func(*args, **kwds)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\alexw\coding\typing_extensions\src\typing_extensions.py", line 672, in __class_getitem__
raise TypeError(
TypeError: Parameters to Protocol[...] must all be type variables. Parameter 1 is *Ts |
typing_extensions.Protocol
with a ParamSpec
on py310+typing_extensions.Protocol
with a ParamSpec
or TypeVarTuple
on py310+
Thanks @AlexWaygood for investigating! Are you working on a fix? |
I am looking into several potential fixes... As usual with I also have a busy day at work, so might not be able to look at this properly until this evening! |
No hurry, I can give it a try later today too. We'll probably want to release a bugfix 4.6.1 with this fix. |
One possible fix involves copying over the logic for I looked into whether we could instead inherit from |
They're probably mostly referring to #179, not this issue. |
Possible, #158 would probably have been a more fitting issue for the screenshot. But I claim innocence in any case. :) |
Oh, I'm definitely guilty for this bug, if we're pointing fingers 😅 I agree with @JelleZijlstra though, there seems to be far more breakage from pydantic/pydantic#5821 than from this issue! |
I have a fix in the works now. |
Originally posted by @Tenzer in #137 (comment)
The text was updated successfully, but these errors were encountered: