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

reveal_type(x) where x: Tuple[int, ...] doesn't show "..." #9522

Closed
gvanrossum opened this issue Oct 1, 2020 · 1 comment · Fixed by #11857
Closed

reveal_type(x) where x: Tuple[int, ...] doesn't show "..." #9522

gvanrossum opened this issue Oct 1, 2020 · 1 comment · Fixed by #11857
Labels
bug mypy got something wrong priority-1-normal

Comments

@gvanrossum
Copy link
Member

Bug Report

Using reveal_type() on a variable whose type is a variable-length tuple shows misleading output.

While it's different from the output for a fixed-length tuple (which shows Tuple[builtins.int]), it doesn't clearly indicate that the type is variable-length.

Note that with PEP 585 accepted, eventually we'll have to use builtins.tuple (or, I'd recomment, plain tuple) for both situations.

To Reproduce

from typing import Tuple
a: Tuple[int, ...]
reveal_type(a)

Expected Behavior

t.py:3: note: Revealed type is 'builtins.tuple[builtins.int, ...]'

or

t.py:3: note: Revealed type is 'Tuple[builtins.int, ...]'

Actual Behavior

t.py:3: note: Revealed type is 'builtins.tuple[builtins.int]'

Your Environment

Master or 0.782, no flags.

@gvanrossum gvanrossum added the bug mypy got something wrong label Oct 1, 2020
@hauntsaninja
Copy link
Collaborator

It looks like mypy uses builtins.tuple as a homogenous tuple type:

if len(t.args) == 2 and isinstance(t.args[1], EllipsisType):
Seems possibly worrisome for transitioning to the PEP 585 world, eg #9459

hauntsaninja pushed a commit that referenced this issue Dec 29, 2021
Previously variadic tuples were displayed as `builtins.tuple[T]`, which
is misleading. That syntax ordinarily indicates a tuple with a single
element. This change adds the `...` ellipsis when formatting.

The formatting of non-variadic tuples is unchanged (e.g. `Tuple[T, U]`).

Fixes #9522
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this issue Jan 20, 2022
Previously variadic tuples were displayed as `builtins.tuple[T]`, which
is misleading. That syntax ordinarily indicates a tuple with a single
element. This change adds the `...` ellipsis when formatting.

The formatting of non-variadic tuples is unchanged (e.g. `Tuple[T, U]`).

Fixes python#9522
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-1-normal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants