-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
Bug Report
attrs.define has slots=True by default. Mypy does not use the default value when analysing
To Reproduce
# demo.py
import attr
@attr.define
class A:
x: int
def __init__(self, x :int) -> None:
self.x = x # ok
self.y = 0 # slots error
A(1)Expected Behavior
$ mypy --strict demo.py
demo.py:9: error: Trying to assign name "y" that is not in "__slots__" of type "demo.A" [misc]
Found 1 error in 1 file (checked 1 source file)Actual Behavior
$ mypy --strict demo.py
Success: no issues found in 1 source file
$ python3 demo.py
Traceback (most recent call last):
File "demo.py", line 11, in <module>
A(1)
File "demo.py", line 9, in __init__
self.y = 0 # slots error
AttributeError: 'A' object has no attribute 'y'Adding (slots=True) to the define decorator results in mypy correctly diagnosing the slots violation:
# demo.py
import attr
@attr.define(slots=True)
class A:
x: int
def __init__(self, x :int) -> None:
self.x = x # ok
self.y = 0 # slots error
A(1)$ mypy --strict demo.py
demo.py:9: error: Trying to assign name "y" that is not in "__slots__" of type "demo.A" [misc]
Found 1 error in 1 file (checked 1 source file)Your Environment
$ mypy --version
mypy 1.4.1 (compiled: yes)
$ python3 --version
Python 3.10.6