-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Open
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
The following example raises a TypeError: Some type variables (T) are not listed in Generic[U]:
class Bar[T, S=T]: ...
class Baz[U](Bar[U]): ...Full Traceback
Traceback (most recent call last):
File "/home/rscholz/Downloads/tmp.py", line 3, in <module>
class Baz[U](Bar[U]): ...
File "/home/rscholz/Downloads/tmp.py", line 3, in <generic parameters of Baz>
class Baz[U](Bar[U]): ...
File "/usr/lib/python3.13/typing.py", line 1288, in _generic_init_subclass
raise TypeError(f"Some type variables ({s_vars}) are"
f" not listed in Generic[{s_args}]")
TypeError: Some type variables (T) are not listed in Generic[U]
The PEP states that
non-overridden defaults should be substituted in, and type parameters with such defaults can be further specialised down the line.
And the typing spec uses similar phrasing, which makes me believe this is a bug. In the example above, I'd expect that Baz[U] is a Bar[U, U] by substitution + default.
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error