Skip to content

Union of different-length Tuple types should agree for corresponding items #2509

Closed
@gvanrossum

Description

@gvanrossum

See python/typeshed#721 (comment). The issue is that after

T = Union[Tuple[int, int], Tuple[int, int, str]]
def f() -> T: pass
a = f()
reveal_type(a[0])
reveal_type(a[2])

the item types are considered to be Any. A better approach would be to understand that a[0] is always an int while a[2] is invalid without some check (however we can't do isinstance() checks on tuple lengths so that's problematic).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions