You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Substitution does not work after ParamSpec substitution of the user generic with a list of TypeVars #88965
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2021-08-01.11:37:51.360>labels= ['type-bug', 'library', '3.10', '3.11']
title='Substitution does not work after ParamSpec substitution of the user generic with a list of TypeVars'updated_at=<Date2021-08-01.11:37:51.360>user='https://github.com/serhiy-storchaka'
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")
>>> classX(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
Activity
serhiy-storchaka commentedon Aug 1, 2021
If the user generic with ParamSpec parameter substituted with a parametrised list containing TypeVar, that TypeVar cannot be substituted.
Expected result equal to X[[int, str]].
LeeeeT commentedon Nov 11, 2022
Hi there! I'm experiencing the same issue. Will this be fixed? @serhiy-storchaka
pythongh-88965: Fix type substitution of a list of types after initia…
gh-88965: typing: fix type substitution of a list of types after init…
pythongh-88965: typing: fix type substitution of a list of types afte…
AlexWaygood commentedon Mar 23, 2023
Fixed on
mainand 3.11, but we've decided not to backport to 3.10.gh-88965: typing: fix type substitution of a list of types after init…
LeeeeT commentedon Mar 23, 2023
Thanks! You guys are awesome! ❤️
AlexWaygood commentedon Mar 23, 2023
@sobolevn gets all the credit on this one :)
pythongh-88965: typing: fix type substitution of a list of types afte…
pythongh-88965: typing: fix type substitution of a list of types afte…