Skip to content

Pyrefly should promote literals when inferring tuple types for attributes #1494

Description

@rchen152

Describe the Bug

Pyrefly doesn't allow this, but I think it should:

class A:
    def __init__(self):
        self.x = (42, 42)
    def f(self):
        self.x = (0, 0)  # error: `tuple[Literal[0], Literal[0]]` is not assignable to attribute `x` with type `tuple[Literal[42], Literal[42]]`

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxlKnHAAQCCiAOuvR-ZjGPQPp8I6CABcBACjgwoYAJSt2nJVJmF89ALz1xAFgBMAGnr7ZbJd15hJ0uQqXKbazdoAMRl7JAGQAVxHQ4EnJEEABiegBVfyhRUnowH3RKf1x0ODY2C3jcACcAW1QxdB887Bgc8XxEeiERWXoAWgA%2BejgRHLtOHJgRHxz2MBYQADkSso76YHwAXyG2LxAybrAoUkIRXDyoCnCABVJl1daMHAJ6SlTIAHM%2BwohUwjZwgGUYGHoACxERYjhEAHp-kseKtCLkrv8YOh-phcJQ4P8LuhrrcUtDsjl6KgAG6oaCobCwc6XCA3HJ3VL0XDENGBNhkEQfVINbHlOD3dhaIYAZkIAEY9HN0CBpt5UMkIKyAGLQGAUNBYPBEMgioA

(Only applicable for extension issues) IDE Information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions