Skip to content

tuple index out of range error is inconsistent #20475

Description

@randolf-scholz

Either both of these should error, or neither of them.

deftest1(items: tuple[int, ...]) ->None:
reveal_type(items[1]) # ✅️reveal_type(items[2]) # ✅️reveal_type(items[3]) # ✅️deftest2(items: tuple[int, *tuple[int, ...]]) ->None:
reveal_type(items[1]) # ❌️ tuple index out of rangereveal_type(items[2]) # ❌️ tuple index out of rangereveal_type(items[3]) # ❌️ tuple index out of range

https://mypy-play.net/?mypy=master&python=3.12&gist=dc9de67cb18ae540cdbb6bc32632eae7

FWIW, only mypy errors here. pyright (strict): no errors, pyrefly no errors, ty: no errors.

Such tuple types can occur naturally, which makes this check prone to false positives, for instance tup=(id, *values), when values is list-like.

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