Hello,

I came up with this fix a little while ago, but haven't gotten a chance to submit my proposed fix until now.

It's very straight-forward. In the existing code, you only check the first item in any node list, when the entire list actually needs to be checked to see if the defining method exists. I just deleted a few lines, added a loop, and bingo, all finished. It fixes the example problem in the ticket description, and I believe it is correct.

I have attached the diff (hg diff > pylint9018.diff). If there's anything else required to get this patch approved (assuming it's good), just let me know.

Thanks,
Scott
diff -r f5f084e5267a checkers/classes.py
--- a/checkers/classes.py       Thu Mar 04 12:12:32 2010 +0100
+++ b/checkers/classes.py       Mon Mar 22 12:55:59 2010 -0400
@@ -179,13 +179,20 @@
                     isinstance(n.statement(), (astng.Delete, astng.AugAssign))]
             if not nodes:
                 continue # error detected by typechecking
-            node = nodes[0] # XXX
-            frame = node.frame()
-            if frame.name not in defining_methods:
+            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):
-                    frame = parent.instance_attrs[attr][0].frame() # XXX
-                    if frame.name in defining_methods:
+                    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:
_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to