Skip to content

Literal (*tuple_of_strings, "string") not assignable to tuple[str, *tuple[str, ...] #21476

@abrahammurciano

Description

@abrahammurciano

Bug Report

Mypy doesn't allow assigning a literal constructed by unpacking a tuple of unknown length mixed with more literals to a variable with a matching tuple type, when the value's unpacking order doesn't exactly match the type expression, even if the resulting tuple's type should match.

To Reproduce

a: tuple[str, ...]
b: tuple[str, *tuple[str, ...]]
b = ("first", *a) # ok
b = (*a, "last") # Incompatible types in assignment (expression has type "tuple[str, ...]", variable has type "tuple[str, *tuple[str, ...]]")

https://mypy-play.net/?mypy=latest&python=3.14&gist=7f1d80e082b57c2c0aa7a3aa38f094be

Actual Behavior

main.py:4: error: Incompatible types in assignment (expression has type "tuple[str, ...]", variable has type "tuple[str, *tuple[str, ...]]") [assignment]

Your Environment

  • Mypy version used: 2.0.0
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-pep-646PEP 646 (TypeVarTuple, Unpack)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions