summaryrefslogtreecommitdiff
path: root/checkers/classes.py
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2015-02-09 22:39:08 +0200
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2015-02-09 22:39:08 +0200
commitfb3bd4b99c74d345ad11eb8fc495b9ca6deffaaf (patch)
tree355d54a6a43d43590fb61e474e805ce7c70210b3 /checkers/classes.py
parent21484711ed52ca8055bc111025a851b37b1278a0 (diff)
downloadpylint-git-fb3bd4b99c74d345ad11eb8fc495b9ca6deffaaf.tar.gz
Use all the inferred statements for the super-init-not-called check.
For the super-init-not-called check, ``next(expr.infer())`` was used, which returned as the first statement an YES node, which resulted in the node being skipped for processing. Inferring all the objects would have returned the actual classes for which the parent was indeed called. This patch changes that to a infer-all strategy, which should yield better results. Closes issue #389.
Diffstat (limited to 'checkers/classes.py')
-rw-r--r--checkers/classes.py41
1 files changed, 21 insertions, 20 deletions
diff --git a/checkers/classes.py b/checkers/classes.py
index 1a10c3576..8e51a47a6 100644
--- a/checkers/classes.py
+++ b/checkers/classes.py
@@ -893,26 +893,27 @@ a metaclass class method.'}
expr.expr.func.name == 'super':
return
try:
- klass = next(expr.expr.infer())
- if klass is YES:
- continue
- # The infered klass can be super(), which was
- # assigned to a variable and the `__init__` was called later.
- #
- # base = super()
- # base.__init__(...)
-
- if (isinstance(klass, astroid.Instance) and
- isinstance(klass._proxied, astroid.Class) and
- is_builtin_object(klass._proxied) and
- klass._proxied.name == 'super'):
- return
- try:
- del not_called_yet[klass]
- except KeyError:
- if klass not in to_call:
- self.add_message('non-parent-init-called',
- node=expr, args=klass.name)
+ for klass in expr.expr.infer():
+ if klass is YES:
+ continue
+ # The infered klass can be super(), which was
+ # assigned to a variable and the `__init__`
+ # was called later.
+ #
+ # base = super()
+ # base.__init__(...)
+
+ if (isinstance(klass, astroid.Instance) and
+ isinstance(klass._proxied, astroid.Class) and
+ is_builtin_object(klass._proxied) and
+ klass._proxied.name == 'super'):
+ return
+ try:
+ del not_called_yet[klass]
+ except KeyError:
+ if klass not in to_call:
+ self.add_message('non-parent-init-called',
+ node=expr, args=klass.name)
except astroid.InferenceError:
continue
for klass, method in six.iteritems(not_called_yet):