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.

authorClaudiu Popa <pcmanticore@gmail.com>
changeset84cb406fd1a0
branchdefault
phasepublic
hiddenno
parent revision#5ad1348455fe Accept only functions and methods for the deprecated-method checker.
child revision#ffe24a7d5a37 Make pylint work with new astroid exceptions, AstroidImportError and AstroidSyntaxError.
files modified by this revision
ChangeLog
pylint/checkers/newstyle.py
pylint/test/functional/super_checks.py
pylint/test/functional/super_checks.txt
# HG changeset patch
# User Claudiu Popa <pcmanticore@gmail.com>
# Date 1449406492 -7200
# Sun Dec 06 14:54:52 2015 +0200
# Node ID 84cb406fd1a0a3b571c35e5eeec5df5ee7772186
# Parent 5ad1348455fe4758b0dcab4051e5f1c33d54dd66
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.

diff --git a/ChangeLog b/ChangeLog
@@ -5,10 +5,13 @@
1       * Accept only functions and methods for the deprecated-method checker.
2 
3        This prevents a crash which can occur when an object doesn't have
4        .qname() method after the inference.
5 
6 +    * Don't emit super-on-old-class on classes with unknown bases.
7 +      Closes issue #721.
8 +
9      * Added a new warning, 'unsupported-assignment-operation', which is
10        emitted when item assignment is tried on an object which doesn't
11        have this ability. Closes issue #591.
12 
13      * Added a new warning, 'unsupported-delete-operation', which is
diff --git a/pylint/checkers/newstyle.py b/pylint/checkers/newstyle.py
@@ -126,16 +126,14 @@
14              # skip the test if using super
15              if not (isinstance(call, astroid.Call) and
16                      isinstance(call.func, astroid.Name) and
17                      call.func.name == 'super'):
18                  continue
19 -            confidence = (INFERENCE if has_known_bases(klass)
20 -                          else INFERENCE_FAILURE)
21 -            if not klass.newstyle:
22 +
23 +            if not klass.newstyle and has_known_bases(klass):                
24                  # super should not be used on an old style class
25 -                self.add_message('super-on-old-class', node=node,
26 -                                 confidence=confidence)
27 +                self.add_message('super-on-old-class', node=node)
28              else:
29                  # super first arg should be the class
30                  if not call.args and sys.version_info[0] == 3:
31                      # unless Python 3
32                      continue
@@ -145,12 +143,11 @@
33                                or None)
34                  except astroid.InferenceError:
35                      continue
36 
37                  if supcls is None:
38 -                    self.add_message('missing-super-argument', node=call,
39 -                                     confidence=confidence)
40 +                    self.add_message('missing-super-argument', node=call)
41                      continue
42 
43                  if klass is not supcls:
44                      name = None
45                      # if supcls is not YES, then supcls was infered
@@ -160,12 +157,11 @@
46                          name = supcls.name
47                      else:
48                          if hasattr(call.args[0], 'name'):
49                              name = call.args[0].name
50                      if name is not None:
51 -                        self.add_message('bad-super-call', node=call, args=(name, ),
52 -                                         confidence=confidence)
53 +                        self.add_message('bad-super-call', node=call, args=(name, ))
54 
55 
56  def register(linter):
57      """required method to auto register this checker """
58      linter.register_checker(NewStyleConflictChecker(linter))
diff --git a/pylint/test/functional/super_checks.py b/pylint/test/functional/super_checks.py
@@ -63,13 +63,13 @@
59 
60 
61  class UnknownBases(Missing):
62      """Don't emit if we don't know all the bases."""
63      def __init__(self):
64 -        # pylint: disable=super-on-old-class
65          super(UnknownBases, self).__init__()
66          super(UnknownBases, self).test()
67 +        super(Missing, self).test() # [bad-super-call]
68 
69 
70  # Test that we are detecting proper super errors.
71 
72  class BaseClass(object):
diff --git a/pylint/test/functional/super_checks.txt b/pylint/test/functional/super_checks.txt
@@ -1,18 +1,19 @@
73  old-style-class:6:Aaaa:Old-style class defined.
74 -super-on-old-class:8:Aaaa.hop:Use of super on an old style class:INFERENCE
75 +super-on-old-class:8:Aaaa.hop:Use of super on an old style class
76  no-member:10:Aaaa.hop:Super of 'Aaaa' has no 'hop' member:INFERENCE
77 -super-on-old-class:12:Aaaa.__init__:Use of super on an old style class:INFERENCE
78 +super-on-old-class:12:Aaaa.__init__:Use of super on an old style class
79  no-member:19:NewAaaa.hop:Super of 'NewAaaa' has no 'hop' member:INFERENCE
80 -bad-super-call:22:NewAaaa.__init__:Bad first argument 'Aaaa' given to super():INFERENCE
81 -missing-super-argument:27:Py3kAaaa.__init__:Missing argument to super():INFERENCE
82 -bad-super-call:32:Py3kWrongSuper.__init__:Bad first argument 'NewAaaa' given to super():INFERENCE
83 -bad-super-call:37:WrongNameRegression.__init__:Bad first argument 'Missing' given to super():INFERENCE
84 -bad-super-call:46:CrashSuper.__init__:Bad first argument 'NewAaaa' given to super():INFERENCE
85 -bad-super-call:62:SuperDifferentScope.test:Bad first argument 'object' given to super():INFERENCE
86 -not-callable:89:InvalidSuperChecks.__init__:super(InvalidSuperChecks, self).not_a_method is not callable:HIGH
87 +bad-super-call:22:NewAaaa.__init__:Bad first argument 'Aaaa' given to super()
88 +missing-super-argument:27:Py3kAaaa.__init__:Missing argument to super()
89 +bad-super-call:32:Py3kWrongSuper.__init__:Bad first argument 'NewAaaa' given to super()
90 +bad-super-call:37:WrongNameRegression.__init__:Bad first argument 'Missing' given to super()
91 +bad-super-call:46:CrashSuper.__init__:Bad first argument 'NewAaaa' given to super()
92 +bad-super-call:62:SuperDifferentScope.test:Bad first argument 'object' given to super()
93 +bad-super-call:70:UnknownBases.__init__:Bad first argument 'Missing' given to super()
94 +not-callable:89:InvalidSuperChecks.__init__:super(InvalidSuperChecks, self).not_a_method is not callable
95  no-member:90:InvalidSuperChecks.__init__:Super of 'InvalidSuperChecks' has no 'attribute_error' member:INFERENCE
96 -no-value-for-parameter:92:InvalidSuperChecks.__init__:No value for argument 'param' in method call:HIGH
97 -too-many-function-args:93:InvalidSuperChecks.__init__:Too many positional arguments for method call:HIGH
98 -no-value-for-parameter:95:InvalidSuperChecks.__init__:No value for argument 'param' in method call:HIGH
99 -unexpected-keyword-arg:95:InvalidSuperChecks.__init__:Unexpected keyword argument 'lala' in method call:HIGH
100 +no-value-for-parameter:92:InvalidSuperChecks.__init__:No value for argument 'param' in method call
101 +too-many-function-args:93:InvalidSuperChecks.__init__:Too many positional arguments for method call
102 +no-value-for-parameter:95:InvalidSuperChecks.__init__:No value for argument 'param' in method call
103 +unexpected-keyword-arg:95:InvalidSuperChecks.__init__:Unexpected keyword argument 'lala' in method call
104  no-member:98:InvalidSuperChecks.__init__:Super of 'InvalidSuperChecks' has no 'attribute_error' member:INFERENCE
105 \ No newline at end of file