diff options
author | cpopa <devnull@localhost> | 2014-07-01 13:35:52 +0300 |
---|---|---|
committer | cpopa <devnull@localhost> | 2014-07-01 13:35:52 +0300 |
commit | 7f71cbb5cc39d981a544c6a1af50521a132ba44d (patch) | |
tree | 6dec69182bcedb55d0b5d952ebc005eaf070557e /checkers/classes.py | |
parent | f607ae828edb94f36732ca2797c5b010e1a49fa4 (diff) | |
download | pylint-7f71cbb5cc39d981a544c6a1af50521a132ba44d.tar.gz |
Emit attribute-defined-outside-init for all cases, not just for the last assignment. Closes issue #262.
Diffstat (limited to 'checkers/classes.py')
-rw-r--r-- | checkers/classes.py | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/checkers/classes.py b/checkers/classes.py index f5e2783..02d304b 100644 --- a/checkers/classes.py +++ b/checkers/classes.py @@ -272,28 +272,30 @@ a metaclass class method.'} isinstance(n.statement(), (astroid.Delete, astroid.AugAssign))] if not nodes: continue # error detected by typechecking - attr_defined = False # check if any method attr is defined in is a defining method - for node in nodes: - if node.frame().name in defining_methods: - attr_defined = True - if not attr_defined: - # check attribute is defined in a parent's __init__ - for parent in cnode.instance_attr_ancestors(attr): - attr_defined = False - # check if any parent method attr is defined in is a defining method - for node in parent.instance_attrs[attr]: - if node.frame().name in defining_methods: - attr_defined = True - if attr_defined: - # we're done :) - break - else: - # check attribute is defined as a class attribute - try: - cnode.local_attr(attr) - except astroid.NotFoundError: - self.add_message('attribute-defined-outside-init', args=attr, node=node) + if any(node.frame().name in defining_methods + for node in nodes): + continue + + # check attribute is defined in a parent's __init__ + for parent in cnode.instance_attr_ancestors(attr): + attr_defined = False + # check if any parent method attr is defined in is a defining method + for node in parent.instance_attrs[attr]: + if node.frame().name in defining_methods: + attr_defined = True + if attr_defined: + # we're done :) + break + else: + # check attribute is defined as a class attribute + try: + cnode.local_attr(attr) + except astroid.NotFoundError: + for node in nodes: + if node.frame().name not in defining_methods: + self.add_message('attribute-defined-outside-init', + args=attr, node=node) def visit_function(self, node): """check method arguments, overriding""" |