Skip to content

User generic with TypeVarTuple does not check for minimal type of arguments #99382

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

Closed
serhiy-storchaka opened this issue Nov 11, 2022 · 2 comments
Labels
3.11 only security fixes 3.12 only security fixes topic-typing type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

The following code:

from typing import *
T = TypeVar('T')
T2 = TypeVar('T2')
Ts = TypeVarTuple('Ts')
class A(Generic[T, T2, *Ts]):
    x: List[T]
    y: List[T2]
    z: Tuple[*Ts]

A[int]

is executed without errors. It is expected to get an error because A requires at least two arguments.

Without TypeVarTuple you get helpful errors.

class B(Generic[T, T2]):
    pass

B[int]
B[int, str, bytes]
TypeError: Too few arguments for <class '__main__.B'>; actual 1, expected 2
TypeError: Too many arguments for <class '__main__.B'>; actual 3, expected 2
@serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error 3.11 only security fixes topic-typing 3.12 only security fixes labels Nov 11, 2022
@sobolevn
Copy link
Member

The code says this:

cpython/Lib/typing.py

Lines 1833 to 1836 in f531b68

# We only run this if there are no TypeVarTuples, because we
# don't check variadic generic arity at runtime (to reduce
# complexity of typing.py).
_check_generic(cls, params, len(cls.__parameters__))

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.
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>
Fatal1ty added a commit to Fatal1ty/mashumaro that referenced this issue Dec 19, 2022
@AlexWaygood
Copy link
Member

I believe that this has been fixed and backported (in #99412 and #99866). Closing as completed.

(Feel free to reopen if I'm incorrect.)

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 only security fixes topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy