summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcpopa <devnull@localhost>2014-08-16 00:25:57 +0300
committercpopa <devnull@localhost>2014-08-16 00:25:57 +0300
commit91af7c933718f518c819fd9eb9f3aa3dd967f43b (patch)
tree10fc0033740d0676c9e2d5c7f0e9ba4fd5a50eae
parent5550b7e0257017b375f9a3cfad68f9cb2ad435a2 (diff)
downloadpylint-91af7c933718f518c819fd9eb9f3aa3dd967f43b.tar.gz
Detect calls of the parent's __init__, through a binded super() call.
-rw-r--r--ChangeLog3
-rw-r--r--checkers/classes.py11
-rw-r--r--test/input/func_w0233.py14
-rw-r--r--test/messages/func_w0233.txt1
4 files changed, 29 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index f7c3b90..c6b9b03 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -66,6 +66,9 @@ ChangeLog for Pylint
* Don't emit 'protected-access' if the attribute is accessed using
a property defined at the class level.
+ * Detect calls of the parent's __init__, through a binded super() call.
+
+
2014-07-26 -- 1.3.0
* Allow hanging continued indentation for implicitly concatenated
diff --git a/checkers/classes.py b/checkers/classes.py
index ebca3f2..d9ebd8d 100644
--- a/checkers/classes.py
+++ b/checkers/classes.py
@@ -818,6 +818,17 @@ a metaclass class method.'}
klass = expr.expr.infer().next()
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:
diff --git a/test/input/func_w0233.py b/test/input/func_w0233.py
index 857743a..ef5f205 100644
--- a/test/input/func_w0233.py
+++ b/test/input/func_w0233.py
@@ -34,3 +34,17 @@ class DDDD(AAAA):
AAAA.__init__(self)
else:
AAAA.__init__(self)
+
+class Super(dict):
+ """ test late binding super() call """
+ def __init__(self):
+ base = super()
+ base.__init__()
+
+class Super2(dict):
+ """ Using the same idiom as Super, but without calling
+ the __init__ method.
+ """
+ def __init__(self):
+ base = super()
+ base.__woohoo__()
diff --git a/test/messages/func_w0233.txt b/test/messages/func_w0233.txt
index 614ceac..157b270 100644
--- a/test/messages/func_w0233.txt
+++ b/test/messages/func_w0233.txt
@@ -2,3 +2,4 @@ E: 22:CCC: Module 'input.func_w0233' has no 'BBBB' member
E: 27:CCC.__init__: Module 'input.func_w0233' has no 'BBBB' member
F: 20: Unable to import 'nonexistant'
W: 12:AAAA.__init__: __init__ method from a non direct base class 'BBBBMixin' is called
+W: 48:Super2.__init__: __init__ method from base class 'dict' is not called \ No newline at end of file