summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2019-09-30 09:21:52 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2019-09-30 09:27:21 +0200
commit4ec293ce4700bfaca89d01c45e707f40c2913d49 (patch)
tree4ec689873581cb2ec2a0a03b7c1e3ec82b0960bc
parent1d3b07a7280a1aad5eed1e937b8161113d1f049e (diff)
downloadpylint-git-4ec293ce4700bfaca89d01c45e707f40c2913d49.tar.gz
Exempt annotated assignments without variable from ``class-variable-slots-conflict``
Close #3141
-rw-r--r--ChangeLog4
-rw-r--r--pylint/checkers/classes.py7
-rw-r--r--tests/functional/c/class_variable_slots_conflict_exempted.py4
3 files changed, 14 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index cb8b79461..5189034a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,10 @@ Release date: TBA
Close #3145
+* Exempt annotated assignments without variable from ``class-variable-slots-conflict``
+
+ Close #3141
+
What's New in Pylint 2.4.1?
===========================
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py
index b8ff1712d..986809fd3 100644
--- a/pylint/checkers/classes.py
+++ b/pylint/checkers/classes.py
@@ -1135,9 +1135,14 @@ a metaclass class method.",
"invalid-slots-object", args=inferred.as_string(), node=elt
)
- # Check if we have a conflict with a class variable
+ # Check if we have a conflict with a class variable.
class_variable = node.locals.get(inferred.value)
if class_variable:
+ # Skip annotated assignments which don't conflict at all with slots.
+ if len(class_variable) == 1:
+ parent = class_variable[0].parent
+ if isinstance(parent, astroid.AnnAssign) and parent.value is None:
+ return
self.add_message(
"class-variable-slots-conflict", args=(inferred.value,), node=elt
)
diff --git a/tests/functional/c/class_variable_slots_conflict_exempted.py b/tests/functional/c/class_variable_slots_conflict_exempted.py
new file mode 100644
index 000000000..b6a0edf44
--- /dev/null
+++ b/tests/functional/c/class_variable_slots_conflict_exempted.py
@@ -0,0 +1,4 @@
+# pylint: disable=missing-docstring,too-few-public-methods
+class Example:
+ __slots__ = ["field"]
+ field: int