Skip to content

Commit

Permalink
Exempt annotated assignments without variable from ``class-variable-s…
Browse files Browse the repository at this point in the history
…lots-conflict``

Close #3141
  • Loading branch information
PCManticore committed Sep 30, 2019
1 parent 1d3b07a commit 4ec293c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -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?
===========================
Expand Down
7 changes: 6 additions & 1 deletion pylint/checkers/classes.py
Expand Up @@ -1135,9 +1135,14 @@ def _check_slots_elt(self, elt, node):
"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
)
Expand Down
4 changes: 4 additions & 0 deletions 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

0 comments on commit 4ec293c

Please sign in to comment.