Skip to content
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

TypeVarTuple and ParamSpec don't work together #99344

Closed
LeeeeT opened this issue Nov 10, 2022 · 3 comments
Closed

TypeVarTuple and ParamSpec don't work together #99344

LeeeeT opened this issue Nov 10, 2022 · 3 comments
Assignees
Labels
3.11 only security fixes 3.12 bugs and security fixes stdlib Python modules in the Lib dir topic-typing type-bug An unexpected behavior, bug, or error

Comments

@LeeeeT
Copy link

LeeeeT commented Nov 10, 2022

Bug report

The following code gives me an error:

from typing import Generic, TypeVarTuple, ParamSpec


Ts = TypeVarTuple("Ts")

P = ParamSpec("P")


class Foo(Generic[*Ts, P]):
    pass


Foo[int, str, [bytes]]
TypeError: Too many arguments for <class 'Foo'>; actual 3, expected 2

I don't see any reasons why it doesn't work with ParamSpec. I believe it should assign int, str to Ts and [bytes] to P.

Environment

  • CPython versions tested on: 3.11
  • Operating system and architecture: Linux x86_64
@LeeeeT LeeeeT added the type-bug An unexpected behavior, bug, or error label Nov 10, 2022
@AlexWaygood AlexWaygood added topic-typing stdlib Python modules in the Lib dir labels Nov 10, 2022
@JelleZijlstra
Copy link
Member

cc @mrahtz @serhiy-storchaka

@AlexWaygood AlexWaygood added 3.11 only security fixes 3.12 bugs and security fixes labels Nov 10, 2022
@serhiy-storchaka serhiy-storchaka self-assigned this Nov 11, 2022
@serhiy-storchaka
Copy link
Member

Yes, such case is just not supported in the code, and it needs a nontrivial rewriting. I have found also several other similar bugs. I am working on the solution, PRs are almost ready.

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Nov 12, 2022
…ution of ParamSpec

and TypeVarTuple

* Fix substitution of TypeVarTuple and ParamSpec together in user generics.

* Fix substitution of ParamSpec followed by TypeVarTuple in generic aliases.

* Check the number of arguments in substitution in user generics containing a
  TypeVarTuple and one or more TypeVar.
@mrahtz
Copy link
Contributor

mrahtz commented Nov 12, 2022

Thank you for taking care of this, Serhiy!

serhiy-storchaka added a commit that referenced this issue Nov 29, 2022
… and TypeVarTuple (GH-99412)

* Fix substitution of TypeVarTuple and ParamSpec together in user generics.

* Fix substitution of ParamSpec followed by TypeVarTuple in generic aliases.

* Check the number of arguments in substitution in user generics containing a
  TypeVarTuple and one or more TypeVar.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 29, 2022
…ution of ParamSpec and TypeVarTuple (pythonGH-99412)

* Fix substitution of TypeVarTuple and ParamSpec together in user generics.

* Fix substitution of ParamSpec followed by TypeVarTuple in generic aliases.

* Check the number of arguments in substitution in user generics containing a
  TypeVarTuple and one or more TypeVar.
(cherry picked from commit 8f2fb7d)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 29, 2022
…ution of ParamSpec and TypeVarTuple (pythonGH-99412)

* Fix substitution of TypeVarTuple and ParamSpec together in user generics.

* Fix substitution of ParamSpec followed by TypeVarTuple in generic aliases.

* Check the number of arguments in substitution in user generics containing a
  TypeVarTuple and one or more TypeVar.
(cherry picked from commit 8f2fb7d)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington added a commit that referenced this issue Nov 29, 2022
… and TypeVarTuple (GH-99412)

* Fix substitution of TypeVarTuple and ParamSpec together in user generics.

* Fix substitution of ParamSpec followed by TypeVarTuple in generic aliases.

* Check the number of arguments in substitution in user generics containing a
  TypeVarTuple and one or more TypeVar.
(cherry picked from commit 8f2fb7d)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and 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

5 participants