Skip to content

Improve error message when variable-length tuple annotation is required #12501

@AlexWaygood

Description

@AlexWaygood

Mypy currently does not give a particularly friendly error message for this snippet of code:

test = (1, 2)
test += (3,)  # error: Incompatible types in assignment (expression has type "Tuple[int, int, int]", variable has type "Tuple[int, int]")

What the user probably needs to do is to add a variable-length tuple annotation, e.g.

test: tuple[int, ...] = (1, 2)
test += (3,)

However, the error message gives no indication of that (on mypy 0.941).

Refs #10384

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions