-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Open
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
This is as minimal as I was able to get the repro. I'm suppose it speaks for itself:
from typing import Generic, Protocol, TypeVar
T1 = TypeVar("T1")
T2 = TypeVar("T2", default=object)
class A(Protocol[T1]): ...
class B1(A[T2], Protocol, Generic[T1, T2]): ... # the workaround
class B2(A[T2], Protocol[T1, T2]): ... # the problem
B1[str] # ok
B2[str] # TypeError
on 3.13.5
:
Traceback (most recent call last):
File "/home/joren/huh.py", line 11, in <module>
B2[str] # TypeError
~~^^^^^
File "/home/joren/.pyenv/versions/3.13.5/lib/python3.13/typing.py", line 432, in inner
return func(*args, **kwds)
File "/home/joren/.pyenv/versions/3.13.5/lib/python3.13/typing.py", line 1242, in _generic_class_getitem
args = prepare(cls, args)
TypeError: Too few arguments for <class '__main__.B2'>; actual 1, expected at least 2
on 3.14.0rc1
:
Traceback (most recent call last):
File "/home/joren/huh.py", line 11, in <module>
B2[str] # TypeError
~~^^^^^
File "/home/joren/.pyenv/versions/3.14.0rc1/lib/python3.14/typing.py", line 401, in inner
return func(*args, **kwds)
File "/home/joren/.pyenv/versions/3.14.0rc1/lib/python3.14/typing.py", line 1133, in _generic_class_getitem
args = prepare(cls, args)
TypeError: Too few arguments for <class '__main__.B2'>; actual 1, expected at least 2
As the repro shows, the workaround is to parametrize an additional Generic
instead of Protocol
.
CPython versions tested on:
3.13, 3.14
Operating systems tested on:
Linux
Linked PRs
KotlinIsland and leycec
Metadata
Metadata
Assignees
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error