summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcpopa <devnull@localhost>2014-04-22 20:35:29 +0300
committercpopa <devnull@localhost>2014-04-22 20:35:29 +0300
commitd49f2971afcbb271fc85496ed8fe8f6b42e7362f (patch)
treebdece89b14de02f72754d42695b7e12624bd43f3
parent25901640d4fce4aa15271e2ff882cdf53c6c64ab (diff)
downloadpylint-d49f2971afcbb271fc85496ed8fe8f6b42e7362f.tar.gz
Fix a potential crash with super inference.
-rw-r--r--checkers/newstyle.py15
-rw-r--r--test/input/func_newstyle_super.py9
-rw-r--r--test/messages/func_newstyle_super.txt3
-rw-r--r--test/messages/func_newstyle_super_py30.txt1
4 files changed, 25 insertions, 3 deletions
diff --git a/checkers/newstyle.py b/checkers/newstyle.py
index 8bdbb25..f801c44 100644
--- a/checkers/newstyle.py
+++ b/checkers/newstyle.py
@@ -131,8 +131,19 @@ class NewStyleConflictChecker(BaseChecker):
continue
if klass is not supcls:
- self.add_message('bad-super-call', node=call,
- args=(call.args[0].name, ))
+ name = None
+ # if supcls is not YES, then supcls was infered
+ # and use its name. Otherwise, try to look
+ # for call.args[0].name
+ if supcls is not astroid.YES:
+ name = supcls.name
+ else:
+ if hasattr(call.args[0], 'name'):
+ name = call.args[0].name
+ if name is not None:
+ self.add_message('bad-super-call',
+ node=call,
+ args=(name, ))
def register(linter):
diff --git a/test/input/func_newstyle_super.py b/test/input/func_newstyle_super.py
index a0aaa0a..10e9b28 100644
--- a/test/input/func_newstyle_super.py
+++ b/test/input/func_newstyle_super.py
@@ -36,3 +36,12 @@ class WrongNameRegression(Py3kAaaa):
""" test a regression with the message """
def __init__(self):
super(Missing, self).__init__()
+
+class Getattr(object):
+ """ crash """
+ name = NewAaaa
+
+class CrashSuper(object):
+ """ test a crash with this checker """
+ def __init__(self):
+ super(Getattr.name, self).__init__()
diff --git a/test/messages/func_newstyle_super.txt b/test/messages/func_newstyle_super.txt
index b51869b..ce71293 100644
--- a/test/messages/func_newstyle_super.txt
+++ b/test/messages/func_newstyle_super.txt
@@ -4,4 +4,5 @@ E: 13:Aaaa.__init__: Use of super on an old style class
E: 23:NewAaaa.__init__: Bad first argument 'object' given to super()
E: 28:Py3kAaaa.__init__: Missing argument to super()
E: 33:Py3kWrongSuper.__init__: Bad first argument 'NewAaaa' given to super()
-E: 38:WrongNameRegression.__init__: Bad first argument 'Missing' given to super() \ No newline at end of file
+E: 38:WrongNameRegression.__init__: Bad first argument 'Missing' given to super()
+E: 47:CrashSuper.__init__: Bad first argument 'NewAaaa' given to super() \ No newline at end of file
diff --git a/test/messages/func_newstyle_super_py30.txt b/test/messages/func_newstyle_super_py30.txt
index b1ee6cd..ecabca5 100644
--- a/test/messages/func_newstyle_super_py30.txt
+++ b/test/messages/func_newstyle_super_py30.txt
@@ -1,3 +1,4 @@
E: 23:NewAaaa.__init__: Bad first argument 'object' given to super()
E: 33:Py3kWrongSuper.__init__: Bad first argument 'NewAaaa' given to super()
E: 38:WrongNameRegression.__init__: Bad first argument 'Missing' given to super()
+E: 47:CrashSuper.__init__: Bad first argument 'NewAaaa' given to super() \ No newline at end of file