Skip to content

Allow non-literals when indexing uniform tuples #899

Closed
@JukkaL

Description

@JukkaL

Currently mypy doesn't allow indexing fixed-length tuples using a non-literal index. We should probably support this at least for tuples with homogeneous types.

For example, code like this should probably be okay:

t = (1, 3, 7)
for i in range(len(t)):
    print(i, t[i])

The example below is actually already valid so rejecting the above code is inconsistent (this works due to how we set the fallback attribute for tuples to be Tuple[t, ...]):

t = (1, 2, 3)
for i, x in enumerate(t):
    print(i, x)

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