summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaarten ter Huurne <maarten@treewalker.org>2010-03-02 01:27:44 +0100
committerMaarten ter Huurne <maarten@treewalker.org>2010-03-02 01:27:44 +0100
commit65cb8eb227ecdacea456950032bcd26b48b555a6 (patch)
tree571f64e77c29d0cf09e05da5dd0a80cc97300fcc
parente10e4a4c304dd37af97ff364a6148492d2fa6cbe (diff)
downloadpylint-65cb8eb227ecdacea456950032bcd26b48b555a6.tar.gz
Fix and test case for W0233 false positive: if the same superclass
constructor was called twice, the second time was reported as a call to a non-existing superclass constructor.
-rw-r--r--checkers/classes.py8
-rw-r--r--test/input/func_w0233.py8
2 files changed, 13 insertions, 3 deletions
diff --git a/checkers/classes.py b/checkers/classes.py
index eb306d5..0609d17 100644
--- a/checkers/classes.py
+++ b/checkers/classes.py
@@ -433,6 +433,7 @@ instance attributes.'}
"""
klass_node = node.parent.frame()
to_call = _ancestors_to_call(klass_node)
+ not_called_yet = dict(to_call)
for stmt in node.nodes_of_class(astng.CallFunc):
expr = stmt.func
if not isinstance(expr, astng.Getattr) \
@@ -448,12 +449,13 @@ instance attributes.'}
if klass is YES:
continue
try:
- del to_call[klass]
+ del not_called_yet[klass]
except KeyError:
- self.add_message('W0233', node=expr, args=klass.name)
+ if klass not in to_call:
+ self.add_message('W0233', node=expr, args=klass.name)
except astng.InferenceError:
continue
- for klass in to_call.keys():
+ for klass in not_called_yet.keys():
if klass.name == 'object':
continue
self.add_message('W0231', args=klass.name, node=node)
diff --git a/test/input/func_w0233.py b/test/input/func_w0233.py
index a667010..3400438 100644
--- a/test/input/func_w0233.py
+++ b/test/input/func_w0233.py
@@ -26,3 +26,11 @@ class CCC(BBBBMixin, func_w0233.AAAA, func_w0233.BBBB, nonexistant.AClass):
func_w0233.AAAA.__init__(self)
func_w0233.BBBB.__init__(self)
nonexistant.AClass.__init__(self)
+
+class DDDD(AAAA):
+ """call superclass constructor in disjunct branches"""
+ def __init__(self, value):
+ if value:
+ AAAA.__init__(self)
+ else:
+ AAAA.__init__(self)