Skip to content

Tuple unpacking loses length and order information #10723

@bersbersbers

Description

@bersbersbers

Describe the bug
Unpacking a tuple and packing to another tuple seem to mess up the typing. It is losing the tuple length information, and seems to mess up the order, too: or why is *i, 2 (2 at the end) inferred as tuple[Literal[2], *tuple[int, ...]] (2 at the front)?

Code or Screenshots

my_dict: dict[tuple[int, int], int] = {}

def foo(i: tuple[int]) -> None:
    my_dict[*i, 2] = 3

foo((1,))
assert my_dict == {(1, 2): 3}

gives

bug.py
  bug.py:4:5 - error: Argument of type "tuple[Literal[2], *tuple[int, ...]]" cannot be assigned to parameter "key" of type "tuple[int, int]" in function "__setitem__"
    "tuple[Literal[2], *tuple[int, ...]]" is not assignable to "tuple[int, int]"
      Tuple size mismatch; expected 2 but received indeterminate (reportArgumentType)
1 error, 0 warnings, 0 informations

VS Code extension or command-line
Python pyright v1.1.403

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions