Skip to content

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

Closed

Description

@antonagestam

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

Activity

  1. srittau commented on Feb 23, 2021

    @srittau
    Contributor

    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 '...'
  2. Akuli commented on Feb 23, 2021

    @Akuli
    Contributor

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

    Maybe this is the problem?

  3. antonagestam commented on Feb 23, 2021

    @antonagestam
    ContributorAuthor

    @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.

  4. changed the title [-]Unexpected '...' for tuple alias [/-] [+]Unexpected '...' for homogeneous tuples using builtin tuple (PEP 585)[/+] on Feb 23, 2021
  5. posita commented on Jun 11, 2021

    @posita
    Contributor

    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
  6. self-assigned this
    on Jul 2, 2021
  7. added a commit that references this issue on Jul 5, 2021
    6eafc5e
  8. sg495 commented on Jul 28, 2021

    @sg495

    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)
    
  9. posita commented on Jul 28, 2021

    @posita
    Contributor

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

  10. MatthieuDartiailh commented on Sep 7, 2021

    @MatthieuDartiailh

    @JukkaL any update on when this will be released ?

  11. ergoithz commented on Oct 24, 2021

    @ergoithz

    @JukkaL any update on when this will be released ?

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

  12. hauntsaninja commented on Oct 31, 2021

    @hauntsaninja
    Collaborator

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

  13. added a commit that references this issue on Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions