diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2014-04-15 18:51:46 +0200 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2014-04-15 18:51:46 +0200 |
commit | 55c07618f5ec8f96c005477c5424449fa7700a4a (patch) | |
tree | 5cf63b275dff250b035d8108f4ca32830d5cafa4 /checkers/classes.py | |
parent | 5a48992e582b5c6dacdca456c7280c74e1f23603 (diff) | |
download | pylint-55c07618f5ec8f96c005477c5424449fa7700a4a.tar.gz |
[classes checker] fix access-member-before-definition false negative wrt aug assign. Closes #164
Diffstat (limited to 'checkers/classes.py')
-rw-r--r-- | checkers/classes.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/checkers/classes.py b/checkers/classes.py index 6dd5df0..f5e2783 100644 --- a/checkers/classes.py +++ b/checkers/classes.py @@ -458,6 +458,10 @@ a metaclass class method.'} self._check_protected_attribute_access(node) + def visit_assattr(self, node): + if isinstance(node.ass_type(), astroid.AugAssign) and self.is_first_attr(node): + self._accessed[-1].setdefault(node.attrname, []).append(node) + @check_messages('protected-access') def visit_assign(self, assign_node): node = assign_node.targets[0] @@ -540,6 +544,19 @@ a metaclass class method.'} except astroid.NotFoundError: pass else: + # filter out augment assignment nodes + defstmts = [stmt for stmt in defstmts if stmt not in nodes] + if not defstmts: + # only augment assignment for this node, no-member should be + # triggered by the typecheck checker + continue + # filter defstmts to only pick the first one when there are + # several assignments in the same scope + scope = defstmts[0].scope() + defstmts = [stmt for i, stmt in enumerate(defstmts) + if i == 0 or stmt.scope() is not scope] + # if there are still more than one, don't attempt to be smarter + # than we can be if len(defstmts) == 1: defstmt = defstmts[0] # check that if the node is accessed in the same method as |