From 46af05ffc1b443290451e19d0a0ca0148e1b2a00 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Sun, 6 Dec 2015 14:54:52 +0200 Subject: Don't emit super-on-old-class on classes with unknown bases. The change also removes the confidence handling for super-on-old-class, which isn't used enough to merit its existence. Closes issue #721. --- ChangeLog | 3 +++ pylint/checkers/newstyle.py | 14 +++++--------- pylint/test/functional/super_checks.py | 2 +- pylint/test/functional/super_checks.txt | 27 ++++++++++++++------------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0e6433e..082c558 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,9 @@ ChangeLog for Pylint This prevents a crash which can occur when an object doesn't have .qname() method after the inference. + * Don't emit super-on-old-class on classes with unknown bases. + Closes issue #721. + * Added a new warning, 'unsupported-assignment-operation', which is emitted when item assignment is tried on an object which doesn't have this ability. Closes issue #591. diff --git a/pylint/checkers/newstyle.py b/pylint/checkers/newstyle.py index 489c22f..5cc8f13 100644 --- a/pylint/checkers/newstyle.py +++ b/pylint/checkers/newstyle.py @@ -128,12 +128,10 @@ class NewStyleConflictChecker(BaseChecker): isinstance(call.func, astroid.Name) and call.func.name == 'super'): continue - confidence = (INFERENCE if has_known_bases(klass) - else INFERENCE_FAILURE) - if not klass.newstyle: + + if not klass.newstyle and has_known_bases(klass): # super should not be used on an old style class - self.add_message('super-on-old-class', node=node, - confidence=confidence) + self.add_message('super-on-old-class', node=node) else: # super first arg should be the class if not call.args and sys.version_info[0] == 3: @@ -147,8 +145,7 @@ class NewStyleConflictChecker(BaseChecker): continue if supcls is None: - self.add_message('missing-super-argument', node=call, - confidence=confidence) + self.add_message('missing-super-argument', node=call) continue if klass is not supcls: @@ -162,8 +159,7 @@ class NewStyleConflictChecker(BaseChecker): 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, ), - confidence=confidence) + self.add_message('bad-super-call', node=call, args=(name, )) def register(linter): diff --git a/pylint/test/functional/super_checks.py b/pylint/test/functional/super_checks.py index 14fd5a2..f4aec0a 100644 --- a/pylint/test/functional/super_checks.py +++ b/pylint/test/functional/super_checks.py @@ -65,9 +65,9 @@ class SuperDifferentScope(object): class UnknownBases(Missing): """Don't emit if we don't know all the bases.""" def __init__(self): - # pylint: disable=super-on-old-class super(UnknownBases, self).__init__() super(UnknownBases, self).test() + super(Missing, self).test() # [bad-super-call] # Test that we are detecting proper super errors. diff --git a/pylint/test/functional/super_checks.txt b/pylint/test/functional/super_checks.txt index a98a25b..ea1d67b 100644 --- a/pylint/test/functional/super_checks.txt +++ b/pylint/test/functional/super_checks.txt @@ -1,18 +1,19 @@ old-style-class:6:Aaaa:Old-style class defined. -super-on-old-class:8:Aaaa.hop:Use of super on an old style class:INFERENCE +super-on-old-class:8:Aaaa.hop:Use of super on an old style class no-member:10:Aaaa.hop:Super of 'Aaaa' has no 'hop' member:INFERENCE -super-on-old-class:12:Aaaa.__init__:Use of super on an old style class:INFERENCE +super-on-old-class:12:Aaaa.__init__:Use of super on an old style class no-member:19:NewAaaa.hop:Super of 'NewAaaa' has no 'hop' member:INFERENCE -bad-super-call:22:NewAaaa.__init__:Bad first argument 'Aaaa' given to super():INFERENCE -missing-super-argument:27:Py3kAaaa.__init__:Missing argument to super():INFERENCE -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 -not-callable:89:InvalidSuperChecks.__init__:super(InvalidSuperChecks, self).not_a_method is not callable:HIGH +bad-super-call:22:NewAaaa.__init__:Bad first argument 'Aaaa' given to super() +missing-super-argument:27:Py3kAaaa.__init__:Missing argument to super() +bad-super-call:32:Py3kWrongSuper.__init__:Bad first argument 'NewAaaa' given to super() +bad-super-call:37:WrongNameRegression.__init__:Bad first argument 'Missing' given to super() +bad-super-call:46:CrashSuper.__init__:Bad first argument 'NewAaaa' given to super() +bad-super-call:62:SuperDifferentScope.test:Bad first argument 'object' given to super() +bad-super-call:70:UnknownBases.__init__:Bad first argument 'Missing' given to super() +not-callable:89:InvalidSuperChecks.__init__:super(InvalidSuperChecks, self).not_a_method is not callable no-member:90:InvalidSuperChecks.__init__:Super of 'InvalidSuperChecks' has no 'attribute_error' member:INFERENCE -no-value-for-parameter:92:InvalidSuperChecks.__init__:No value for argument 'param' in method call:HIGH -too-many-function-args:93:InvalidSuperChecks.__init__:Too many positional arguments for method call:HIGH -no-value-for-parameter:95:InvalidSuperChecks.__init__:No value for argument 'param' in method call:HIGH -unexpected-keyword-arg:95:InvalidSuperChecks.__init__:Unexpected keyword argument 'lala' in method call:HIGH +no-value-for-parameter:92:InvalidSuperChecks.__init__:No value for argument 'param' in method call +too-many-function-args:93:InvalidSuperChecks.__init__:Too many positional arguments for method call +no-value-for-parameter:95:InvalidSuperChecks.__init__:No value for argument 'param' in method call +unexpected-keyword-arg:95:InvalidSuperChecks.__init__:Unexpected keyword argument 'lala' in method call no-member:98:InvalidSuperChecks.__init__:Super of 'InvalidSuperChecks' has no 'attribute_error' member:INFERENCE \ No newline at end of file -- cgit v1.2.1