Skip to content

Bizarre missing-attribute false positive for a class with __slots__ #2950

@superbobry

Description

@superbobry

Describe the Bug

Reproducer:

# m1.py

class A:
 __slots__ = ('ok',)

 def __init__(self, ok: int) -> None:
   self.ok = ok

# m2.py

from m1 import A


class B:
 __slots__ = ('x',)

 def __init__(self, x: int) -> None:
   self.x = x


def f(a: A) -> None:
 a.ok = 1

Output:

$ pyrefly check m1.py m2.py
ERROR Object of class `A` has no attribute `ok` (not declared in `__slots__`) [missing-attribute]
  --> m2.py:12:2
   |
12 |  a.ok = 1
   |  ^^^^
   |
 INFO 1 error

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

Type

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions