Skip to content

Bug or new behavior of generics parameterization? #98852

Description

@Eclips4
fromtypingimportTypeVar, Generic, CallableT=TypeVar("T")
P=TypeVar("P")
classTest(Generic[T]): ...
S=Callable[[Test], P]
deftest(arg: S[T]): ...

On python3.11 i can't run this code. Code falls on an attempt to parameterize S
Traceback:

Traceback (most recent call last):
File "C:\Users\KIRILL-1\PycharmProjects\dataclass_factory\exp.py", line 12, in <module> def test(arg: S[T]): ... ~^^^ File "C:\Users\KIRILL-1\AppData\Local\Programs\Python\Python311\Lib\typing.py", line 360, in inner return cached(*args, **kwds)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\KIRILL-1\AppData\Local\Programs\Python\Python311\Lib\typing.py", line 1391, in __getitem__
new_args = self._determine_new_args(args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\KIRILL-1\AppData\Local\Programs\Python\Python311\Lib\typing.py", line 1440, in _determine_new_args
subargs.append(new_arg_by_param[x])
~~~~~~~~~~~~~~~~^^^
KeyError: ~T

How i understand, in 3.11, an attempt is being made to parameterize Test in S, but in 3.10 - not
Is it new behavior or a bug?

Metadata

Metadata

Labels

3.10only security fixes3.11only security fixes3.12only security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errortype-crashA hard crash of the interpreter, possibly with a core dump

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions