8000 Substitution does not work after ParamSpec substitution of the user generic with a list of TypeVars · Issue #88965 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Substitution does not work after ParamSpec substitution of the user generic with a list of TypeVars #88965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignees
Labels
3.10 only security fixes 3.11 only security fixes 3.12 only security fixes stdlib Python modules in the Lib dir topic-typing type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member
serhiy-storchaka commented Aug 1, 2021
BPO 44802
Nosy @gvanrossum, @serhiy-storchaka, @Fidget-Spinner

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 = None
closed_at = None
created_at = <Date 2021-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 = <Date 2021-08-01.11:37:51.360>
user = 'https://github.com/serhiy-storchaka'

bugs.python.org fields:

activity = <Date 2021-08-01.11:37:51.360>
actor = 'serhiy.storchaka'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2021-08-01.11:37:51.360>
creator = 'serhiy.storchaka'
dependencies = []
files = []
hgrepos = []
issue_num = 44802
keywords = []
message_count = 1.0
messages = ['398694']
nosy_count = 3.0
nosy_names = ['gvanrossum', 'serhiy.storchaka', 'kj']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue44802'
versions = ['Python 3.10', 'Python 3.11']

Linked PRs

@serhiy-storchaka
Copy link
Member Author

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]].

@serhiy-storchaka serhiy-storchaka added 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Aug 1, 2021
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@LeeeeT
Copy link
LeeeeT commented Nov 11, 2022

Hi there! I'm experiencing the same issue. Will this be fixed? @serhiy-storchaka

@serhiy-storchaka serhiy-storchaka self-assigned this Nov 11, 2022
@AlexWaygood AlexWaygood added the 3.12 only security fixes label Mar 15, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Mar 18, 2023
AlexWaygood added a commit that referenced this issue Mar 23, 2023
…ial `ParamSpec` substitution (#102808)

Previously, this used to fail:

```py
from typing import *
T = TypeVar("T")
P = ParamSpec("P")

class X(Generic[P]):
    f: Callable[P, int]

Y = X[[int, T]]
Z = Y[str]
```

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 23, 2023
…r initial `ParamSpec` substitution (pythonGH-102808)

Previously, this used to fail:

```py
from typing import *
T = TypeVar("T")
P = ParamSpec("P")

class X(Generic[P]):
    f: Callable[P, int]

Y = X[[int, T]]
Z = Y[str]
```

(cherry picked from commit adb0621)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@AlexWaygood
Copy link
Member

Fixed on main and 3.11, but we've decided not to backport to 3.10.

miss-islington added a commit that referenced this issue Mar 23, 2023
…ial `ParamSpec` substitution (GH-102808)

Previously, this used to fail:

```py
from typing import *
T = TypeVar("T")
P = ParamSpec("P")

class X(Generic[P]):
    f: Callable[P, int]

Y = X[[int, T]]
Z = Y[str]
```

(cherry picked from commit adb0621)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@LeeeeT
Copy link
LeeeeT commented Mar 23, 2023

Thanks! You guys are awesome! ❤️

@AlexWaygood
Copy link
Member

Thanks! You guys are awesome! ❤️

@sobolevn gets all the credit on this one :)

Fidget-Spinner pushed a commit to Fidget-Spinner/cpython that referenced this issue Mar 27, 2023
…r initial `ParamSpec` substitution (python#102808)

Previously, this used to fail:

```py
from typing import *
T = TypeVar("T")
P = ParamSpec("P")

class X(Generic[P]):
    f: Callable[P, int]

Y = X[[int, T]]
Z = Y[str]
```

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
warsaw pushed a commit to warsaw/cpython that referenced this issue Apr 11, 2023
…r initial `ParamSpec` substitution 
5E60
(python#102808)

Previously, this used to fail:

```py
from typing import *
T = TypeVar("T")
P = ParamSpec("P")

class X(Generic[P]):
    f: Callable[P, int]

Y = X[[int, T]]
Z = Y[str]
```

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes 3.11 only security fixes 3.12 only security fixes stdlib Python modules in the Lib dir topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants
0