[New-bugs-announce] [issue44802] Substitution does not work after ParamSpec substitution of the user generic with a list of TypeVars

Serhiy Storchaka report at bugs.python.org
Sun Aug 1 07:37:51 EDT 2021


New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:

If the user generic with ParamSpec parameter substituted with a parametrised list containing TypeVar, that TypeVar cannot be substituted.

>>> from typing import *
>>> T = TypeVar("T")
>>> P = ParamSpec("P")
>>> class X(Generic[P]):
...     f: Callable[P, int]
... 
>>> Y = X[[int, T]]
>>> Y
__main__.X[(<class 'int'>, ~T)]
>>> Y[str]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython/Lib/typing.py", line 309, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/serhiy/py/cpython/Lib/typing.py", line 1028, in __getitem__
    _check_generic(self, params, len(self.__parameters__))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/serhiy/py/cpython/Lib/typing.py", line 228, in _check_generic
    raise TypeError(f"{cls} is not a generic class")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: __main__.X[(<class 'int'>, ~T)] is not a generic class

Expected result equal to X[[int, str]].

----------
components: Library (Lib)
messages: 398694
nosy: gvanrossum, kj, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Substitution does not work after ParamSpec substitution of the user generic with a list of TypeVars
type: behavior
versions: Python 3.10, Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44802>
_______________________________________


More information about the New-bugs-announce mailing list