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

Unclear error from tuple[int, ...] outside typing context #11703

Closed
PeterJCLaw opened this issue Dec 10, 2021 · 2 comments
Closed

Unclear error from tuple[int, ...] outside typing context #11703

PeterJCLaw opened this issue Dec 10, 2021 · 2 comments
Labels
bug mypy got something wrong

Comments

@PeterJCLaw
Copy link
Contributor

Bug Report

Given tuple[str, ...] outside a typing context mypy produces an error which doesn't seem very clear:

x: tuple[str, ...] = ('',)
y = tuple[str, ...]  # error: Unexpected "..."  [misc]
print(x)
print(y)

Python is quite happy with the code however:

('',)
tuple[str, ...]

Expected Behavior

If this really is considered an error, it would be great to have a bit more detail here about what's gone wrong and why it's a problem.
I'm guessing that catching this and telling the user that they're likely got a type annotation outside a typing context could be useful, however it feels like type aliases (Foo = tuple[int, ...]) might be broken by the current behaviour.

In my case we hit this while partially upgrading an old function-style NamedTuple declaration (to use tuple but not class-style NamedTuple), where the error was particularly confusing as Tuple[int, ...] had worked fine.

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.9
  • Operating system and version: Ubuntu 20.04
@PeterJCLaw PeterJCLaw added the bug mypy got something wrong label Dec 10, 2021
@pranavrajpal
Copy link
Contributor

Could you check what mypy master shows? This looks like the same issue as #9980, which has been fixed for a while.

@PeterJCLaw
Copy link
Contributor Author

Ah, sorry for the duplicate report. Looks like this has indeed been fixed on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants