Skip to content

TypeError when omitting a Protocol type argument with default #137191

Description

@jorenham

Bug report

Bug description:

This is as minimal as I was able to get the repro. I'm suppose it speaks for itself:

fromtypingimportGeneric, Protocol, TypeVarT1=TypeVar("T1")
T2=TypeVar("T2", default=object)
classA(Protocol[T1]): ...
classB1(A[T2], Protocol, Generic[T1, T2]): ... # the workaroundclassB2(A[T2], Protocol[T1, T2]): ... # the problemB1[str] # okB2[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 innerreturn 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 innerreturn 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

Metadata

Metadata

Assignees

Labels

3.15pre-release feature fixes, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions