diff options
author | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2014-12-03 01:48:58 +0200 |
---|---|---|
committer | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2014-12-03 01:48:58 +0200 |
commit | b313d4a9715f3437288744c62fbd105e3307bb4a (patch) | |
tree | 18f126d2de61c7384543e80ed86ea5bf2d5164f6 | |
parent | 5e8bbdb6698a8e005c579621611b40a6f486d118 (diff) | |
download | pylint-b313d4a9715f3437288744c62fbd105e3307bb4a.tar.gz |
Look only in the current function's scope for bad-super-call. Closes issue #403.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | checkers/newstyle.py | 9 | ||||
-rw-r--r-- | test/functional/super_checks.py | 16 | ||||
-rw-r--r-- | test/functional/super_checks.txt | 1 |
4 files changed, 29 insertions, 1 deletions
@@ -1,6 +1,10 @@ ChangeLog for Pylint ==================== +-- + * Look only in the current function's scope for bad-super-call. + Closes issue #403. + 2014-11-23 -- 1.4.0 * Added new options for controlling the loading of C extensions. diff --git a/checkers/newstyle.py b/checkers/newstyle.py index 1656806..f74e7f1 100644 --- a/checkers/newstyle.py +++ b/checkers/newstyle.py @@ -21,7 +21,11 @@ import astroid from pylint.interfaces import IAstroidChecker, INFERENCE, INFERENCE_FAILURE, HIGH from pylint.checkers import BaseChecker -from pylint.checkers.utils import check_messages, has_known_bases +from pylint.checkers.utils import ( + check_messages, + has_known_bases, + node_frame_class, +) MSGS = { 'E1001': ('Use of __slots__ on an old style class', @@ -112,6 +116,9 @@ class NewStyleConflictChecker(BaseChecker): return klass = node.parent.frame() for stmt in node.nodes_of_class(astroid.CallFunc): + if node_frame_class(stmt) != node_frame_class(node): + # Don't look down in other scopes. + continue expr = stmt.func if not isinstance(expr, astroid.Getattr): continue diff --git a/test/functional/super_checks.py b/test/functional/super_checks.py index 287ed5e..368c60c 100644 --- a/test/functional/super_checks.py +++ b/test/functional/super_checks.py @@ -44,3 +44,19 @@ class CrashSuper(object): """ test a crash with this checker """ def __init__(self): super(Getattr.name, self).__init__() # [bad-super-call] + +class Empty(object): + """Just an empty class.""" + +class SuperDifferentScope(object): + """Don'emit bad-super-call when the super call is in another scope. + For reference, see https://bitbucket.org/logilab/pylint/issue/403. + """ + @staticmethod + def test(): + """Test that a bad-super-call is not emitted for this case.""" + class FalsePositive(Empty): + """The following super is in another scope than `test`.""" + def __init__(self, arg): + super(FalsePositive, self).__init__(arg) + super(object, 1).__init__() # [bad-super-call] diff --git a/test/functional/super_checks.txt b/test/functional/super_checks.txt index 79f6ae1..8e7da6c 100644 --- a/test/functional/super_checks.txt +++ b/test/functional/super_checks.txt @@ -6,3 +6,4 @@ missing-super-argument:27:Py3kAaaa.__init__:Missing argument to super():INFERENC bad-super-call:32:Py3kWrongSuper.__init__:Bad first argument 'NewAaaa' given to super():INFERENCE bad-super-call:37:WrongNameRegression.__init__:Bad first argument 'Missing' given to super():INFERENCE bad-super-call:46:CrashSuper.__init__:Bad first argument 'NewAaaa' given to super():INFERENCE +bad-super-call:62:SuperDifferentScope.test:Bad first argument 'object' given to super():INFERENCE |