Skip to content

"Unexpected '...'" reported from ellipsis in type alias, but understood anyway? #10242

@qwertystop

Description

@qwertystop

Bug Report

The type typing.Tuple[Foo, ...] is accepted as meaning "tuple of Foo, arbitrary length", but tuple[Foo, ...] is not, in the context of type aliases. It's apparently understood, but produces an error message anyway.

To Reproduce

Create a file:

from typing import Tuple

IntsA = Tuple[int, ...]
IntsB = tuple[int, ...]

def foo(inputs: tuple[int, ...]) -> IntsB:
    return inputs

Then run mypy on the file.

Actual Behavior

mypy reports: test.py:4: error: Unexpected '...'. It does not report an error on line 3 (alias defined from Tuple) or 5 (the same type provided directly as an annotation rather than an alias, and also the use of the alias which produced an error). If foo is defined as returning something that is not a tuple of integers, such as ("argle",), mypy does report that as an incompatible return value type.

Your Environment

  • Mypy version used: 0.812
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): I have not set up such configuration
  • Python version used: 3.9.0
  • Operating system and version: Arch Linux (linux 5.11.8-arch1-1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions