Closed
Description
from typing import TypeVar, Generic, Callable
T = TypeVar("T")
P = TypeVar("P")
class Test(Generic[T]): ...
S = Callable[[Test], P]
def test(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?