Skip to content

Recursive bounded generic wrongly reported as 'object' #2026

@carlo-nonato

Description

@carlo-nonato

Describe the Bug

class A[T: A]:
    x: int = 1

    def __init__(self, a: T):
        print(a.x)

This gives:

Object of class `object` has no attribute `x` [missing-attribute]

pyrefly seems to ignore the bound of the type parameter of generic class if the type is the class itself.

In the above example, a should be of type A (or subclass) so it should have the x attribute.

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxlKnHAAQCCA2gCqJMC6iAOuvQPr4OEdABd6AXnoBGPn0H1MMMPQD6a0RDEaAFHBhQwAGnqoOrAJS9%2BiwcQBOosbtSF8lkMZBkHKqKSEYrgAtlAUAMT0AAqkfmAB9GhYePj0lLjokADmAK4OqGIQmYR8UQDKMDD0ABZiYsRwiAD0zb7%2BgbgO2c0w6M2YuJRwzRlZEHkFRZnN9GBdZgBuqNCo2LDpmTn5hcX8uMTT6HCl6GRiNZkAtIswDnB7UvQ8IADMhDIATC98IAC%2B3lQlCKtwAYtAYBRkjgCCRyH8gA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions