summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJake Lishman <jake@binhbar.com>2021-12-15 14:11:06 +0000
committerGitHub <noreply@github.com>2021-12-15 15:11:06 +0100
commit7b79386b64db66c38c2095c17fa7d6f7e6083892 (patch)
tree6a5ea86d5a3769bffe9bccece700808fe9dba31f /tests
parentfe547fbc47d9f8389260d38d4237b1b003722035 (diff)
downloadpylint-git-7b79386b64db66c38c2095c17fa7d6f7e6083892.tar.gz
Fix assigning-non-slot false positive with setattr (#5457)
* Fix assigning-non-slot false positive with setattr Previously, if a class was slotted and overrode `__setattr__`, `assigning-non-slot` would be issued when assigning to attributes. With `__setattr__` defined, we cannot infer if it is an error to assign to an attribute, so we suppress the error. Fix #3793 Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/a/assign/assigning_non_slot.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/functional/a/assign/assigning_non_slot.py b/tests/functional/a/assign/assigning_non_slot.py
index cf673692f..2cd1483e0 100644
--- a/tests/functional/a/assign/assigning_non_slot.py
+++ b/tests/functional/a/assign/assigning_non_slot.py
@@ -173,3 +173,30 @@ class Cls(Generic[TYPE]):
def __init__(self, value):
self.value = value
+
+
+class ClassDefiningSetattr(object):
+ __slots__ = ["foobar"]
+
+ def __init__(self):
+ self.foobar = {}
+
+ def __setattr__(self, name, value):
+ if name == "foobar":
+ super().__setattr__(name, value)
+ else:
+ self.foobar[name] = value
+
+
+class ClassWithParentDefiningSetattr(ClassDefiningSetattr):
+ __slots__ = []
+
+
+def dont_emit_for_defined_setattr():
+ inst = ClassDefiningSetattr()
+ # This should not emit because we can't reason about what happens with
+ # classes defining __setattr__
+ inst.non_existent = "non-existent"
+
+ child = ClassWithParentDefiningSetattr()
+ child.non_existent = "non-existent"