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

Tuple[...] is allowed since 3.11+ (gh-31021) #96792

Closed
sobolevn opened this issue Sep 13, 2022 · 2 comments
Closed

Tuple[...] is allowed since 3.11+ (gh-31021) #96792

sobolevn opened this issue Sep 13, 2022 · 2 comments
Assignees
Labels
topic-typing type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Sep 13, 2022

Before TypeVarTuple support was megred, this is what happened when Tuple[...] was used:

Python 3.10.0 (default, Nov  1 2021, 10:24:06) [Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import Tuple
>>> Tuple[...]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/typing.py", line 309, in inner
    return func(*args, **kwds)
  File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/typing.py", line 1210, in __getitem__
    params = tuple(_type_check(p, msg) for p in params)
  File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/typing.py", line 1210, in <genexpr>
    params = tuple(_type_check(p, msg) for p in params)
  File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/typing.py", line 173, in _type_check
    raise TypeError(f"{msg} Got {arg!r:.100}.")
TypeError: Tuple[t0, t1, ...]: each t must be a type. Got Ellipsis.

Since 3.11 it is allowed:

Python 3.12.0a0 (heads/main-dirty:a36235d5c7, Sep 11 2022, 12:23:24) [Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import Tuple
>>> Tuple[...]
typing.Tuple[...]

What should we do?

  1. Keep this as-is, provide a test that this is allowed (I don't know why anyone would use tuple[...])
  2. Make sure that it is still an error with newer version: fix regression and add a test case

In both case I would like to send a PR :)

Related:

CC @JelleZijlstra and @Fidget-Spinner

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error topic-typing labels Sep 13, 2022
@sobolevn sobolevn self-assigned this Sep 13, 2022
@serhiy-storchaka
Copy link
Member

Stricter check was removed in bpo-46644, so now Tuple accepts virtually arbitrary arguments:

>>> Tuple[4]
typing.Tuple[4]

I do not think that it is right.

@JelleZijlstra
Copy link
Member

Thanks for digging that up. This is an intentional change to make the runtime type system more flexible and less opinionated, so that it is easier to evolve it in the future.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants