Skip to content

Incorrect missing-attribute when valid class attribute is included in __slots__ #2444

@jakevdp

Description

@jakevdp

Describe the Bug

Example:

class Foo:
    __slots__ = ["__name__"]

    def __init__(self):
        self.__name__ = "foo_instance"

print(Foo.__name__)

Runtime result:

$ python test.py
Foo

pyrefly check result:

$ pyrefly check test.py
ERROR Instance-only attribute `__name__` of class `Foo` is not visible on the class [missing-attribute]
 --> test.py:7:7
  |
8 | print(Foo.__name__)
  |       ^^^^^^^^^^^^
  |
 INFO 1 error

Sandbox Link

sandbox link

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

googleissues from googletypecheckingv1-verifiedIn both V1 milestone and top-ranked (verified by ranking pipeline)

Type

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions