Skip to content

Pyrefly sometimes loses information about a fixed-length tuple when it is passed through a generic function #1535

@rchen152

Description

@rchen152

Describe the Bug

Example:

from typing import reveal_type

def f[T](x: T) -> T:
    return x

x = (1, "hello world")
reveal_type(f(x))  # this is `tuple[int, str]`

reveal_type(f((1, "hello world")))  # but this is `tuple[Literal[1, "hello world"], ...]`?

In the second case, we've downgraded the tuple to a variable-length one and no longer know the types at specific indices.

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN2UYANxiooAfSbEYAHXRzMMMHTABtACoBdABT5EddQEo6AWgB8BxHLo2BMBgFdK6Ovjlz8dALx1tARgAaOhkQAAsYKChcOgB3XihMEMM5QRExSWYYbTBdQ2T5dFTRCSksnP8gkPDI6LjKBKS8kACQBwZoOBJyRBAAYjoAVXaoCCYVB3QAY3bcdDh3LCUVXhpUBnF0BxpsGEpdfVYGY3M6OAZKKxdbQUdnFRCAOS2di7pgfABfELlmkDJBMBQUiEBi0KAUfoABVIAKBpwwOAIdEms0gbCcawgs0Icn6AGUYDA6KEGAxiHBEAB6Sn-JRAwi8NiUmDoSmYXCTOCUlHoNEYmas5aUOioISoaCobCwZGoiDoyiY2Z0XDEAWdORkBihWYmESUOBYlw%2BEIAZkIfgATN90CAPi1UNMICIAGLQGAUNBYPBEMi2oA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions