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

Unexpected '...' for homogeneous tuples using builtin tuple (PEP 585) #9980

Closed
antonagestam opened this issue Jan 27, 2021 · 9 comments · Fixed by #10766
Closed

Unexpected '...' for homogeneous tuples using builtin tuple (PEP 585) #9980

antonagestam opened this issue Jan 27, 2021 · 9 comments · Fixed by #10766
Assignees
Labels
bug mypy got something wrong priority-0-high

Comments

@antonagestam
Copy link
Contributor

Bug Report

When using builtin tuple to create a type alias, mypy reports an error.

To Reproduce

t = tuple[str, ...]

Expected Behavior

No error.

Actual Behavior

$ mypy <(echo 't = tuple[str, ...]')
/dev/fd/63:1: error: Unexpected '...'  [misc]
    t = tuple[str, ...]
    ^
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 0.800

  • Mypy command-line flags:

  • Mypy configuration options from mypy.ini (and other config files):

    [mypy]
    python_version = 3.9
    show_error_codes = True
    pretty = True
    files = .
    
    ignore_missing_imports = False
    no_implicit_reexport = True
    no_implicit_optional = True
    strict_equality = True
    strict_optional = True
    check_untyped_defs = True
    disallow_incomplete_defs = True
    disallow_untyped_defs = True
    disallow_untyped_calls = True
    disallow_untyped_decorators = True
    disallow_subclassing_any = True
    
    warn_unused_configs = True
    warn_redundant_casts = True
    warn_unused_ignores = True
    warn_return_any = True
    warn_unreachable = True
    
  • Python version used: 3.9.0

  • Operating system and version: Macos 11.1

@srittau
Copy link
Contributor

srittau commented Feb 23, 2021

This seems to affect more than just type aliases. When I tried to change the tuples in typeshed's stdlib/random.pyi, it complained with the same error message. (Using mypy 0.820+dev.9cbf4c0da8f83efd0ba82a91e180b6e96dd15f69 and Python 3.8.3.):

def foo(self) -> tuple[int, ...]: ...  # error: Unexpected '...'
def bar(self, x: tuple[int, ...]) -> None: ...  # error: Unexpected '...'

@Akuli
Copy link
Contributor

Akuli commented Feb 23, 2021

# builtins.tuple[T] is typing.Tuple[T, ...]

Maybe this is the problem?

@antonagestam
Copy link
Contributor Author

antonagestam commented Feb 23, 2021

@srittau Interesting, I noticed it works in some places of our codebase, when I tried isolating them with e.g. mypy <(echo 'ordering: tuple[str, ...] = ("-pk",)' it fails. Might be something else going on that is shadowing those definitions I guess.

That's why I thought this was only happening for type aliases. I'll rename the issue.

@antonagestam antonagestam changed the title Unexpected '...' for tuple alias Unexpected '...' for homogeneous tuples using builtin tuple (PEP 585) Feb 23, 2021
@posita
Copy link
Contributor

posita commented Jun 11, 2021

Is this a dup of #10242? Also, are you still seeing these errors?

def foo(self) -> tuple[int, ...]: ...  # error: Unexpected '...'
def bar(self, x: tuple[int, ...]) -> None: ...  # error: Unexpected '...'

☝️ Those don't appear for me in 0.901, but these do: 👇

% cat -n test.py
     1  from __future__ import annotations
     2
     3  from collections.abc import Callable
     4
     5  _T = tuple[int, ...]  # <- spurious `Unexpected "..."` message
     6  f: Callable[[_T], None] = lambda t: print("{}".format(t))
     7  f((1, 2, 3))
     8  f([1, 2, 3])  # <- still validly caught, apparently
% mypy test.py
test.py:5: error: Unexpected "..."
test.py:8: error: Argument 1 has incompatible type "List[int]"; expected "Tuple[int, ...]"
Found 2 errors in 1 file (checked 1 source file)
% python --version
Python 3.9.5
% mypy --version
mypy 0.901

JishnuM added a commit to MetricRule/metricrule-agent-python that referenced this issue Jun 17, 2021
@JukkaL JukkaL self-assigned this Jul 2, 2021
JukkaL added a commit that referenced this issue Jul 5, 2021
This fixes these issues:

* Allow variable-length tuple (tuple[int, ...]) in type aliases
* Allow generic built-in types (e.g. list[int]) in stubs in all Python versions

Fixes #9980. Fixes #10303. Fixes #10731.
@sg495
Copy link

sg495 commented Jul 28, 2021

This is still happening to me on 0.910. Here is a snippet:

T = tuple[int, ...]

Here are the mypy version check and output:

>mypy --version
mypy 0.910
>mypy test.py
test.py:1: error: Unexpected "..."
Found 1 error in 1 file (checked 1 source file)

@posita
Copy link
Contributor

posita commented Jul 28, 2021

I think the fix was landed after 0.910 was released. @JukkaL, can you confirm whether it will make it into the next one?

@MatthieuDartiailh
Copy link

@JukkaL any update on when this will be released ?

@ergoithz
Copy link

@JukkaL any update on when this will be released ?

Furthermore, any plans on releasing this fix before Python 4?

@hauntsaninja
Copy link
Collaborator

You can follow #11158 for the release. I can promise you that this will be released before Python 4 :D

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-0-high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants