Fix false positive W0231 for missing call to object.__init__. Closes #103656

authorFELD Boris <lothiraldan@gmail.com>
changeset1a27a3d9ea5e
branchdefault
phasepublic
hiddenno
parent revision#4d59dfcc0acc Add test and code for handling __all__ with pylint. Closes #4685.
child revision#dc1a6cb753e0 use .iter* version of dict methods when possible
files modified by this revision
ChangeLog
checkers/classes.py
test/input/func_w0231.py
# HG changeset patch
# User FELD Boris <lothiraldan@gmail.com>
# Date 1348059181 -7200
# Wed Sep 19 14:53:01 2012 +0200
# Node ID 1a27a3d9ea5e88ae0188e2fd393b488da19da344
# Parent 4d59dfcc0acc66356d430cbedcde4eab60be9555
Fix false positive W0231 for missing call to object.__init__. Closes #103656

diff --git a/ChangeLog b/ChangeLog
@@ -12,16 +12,18 @@
1        introducing new E0603 message
2 
3      * #100654: fix grammatical error for W0332 message (using 'l' as
4        long int identifier)
5 
6 +    * #103656: fix W0231 false positive for missing call to object.__init__
7 +      (patch by lothiraldan@gmail.com)
8 +
9      * fix cross-interpreter issue (non compatible access to __builtins__)
10 
11      * stop including tests files in distribution, they causes crash when
12        installed with python3 (#72022, #82417, #76910)
13 
14 -
15  2012-07-17  --  0.25.2
16      * #93591: Correctly emit warnings about clobbered variable names when an
17        except handler contains a tuple of names instead of a single name.
18        (patch by tmarek@google.com)
19 
diff --git a/checkers/classes.py b/checkers/classes.py
@@ -573,12 +573,12 @@
20                  except KeyError:
21                      if klass not in to_call:
22                          self.add_message('W0233', node=expr, args=klass.name)
23              except astng.InferenceError:
24                  continue
25 -        for klass in not_called_yet.keys():
26 -            if klass.name == 'object':
27 +        for klass, method in not_called_yet.iteritems():
28 +            if klass.name == 'object' or method.parent.name == 'object':
29                  continue
30              self.add_message('W0231', args=klass.name, node=node)
31 
32      def _check_signature(self, method1, refmethod, class_type):
33          """check that the signature of the two given methods match
@@ -614,12 +614,11 @@
34      the queried method, and so that should/may be called from the method node
35      """
36      to_call = {}
37      for base_node in klass_node.ancestors(recurs=False):
38          try:
39 -            base_node.local_attr(method)
40 -            to_call[base_node] = 1
41 +            to_call[base_node] = base_node.local_attr(method)[-1]
42          except astng.NotFoundError:
43              continue
44      return to_call
45 
46 
diff --git a/test/input/func_w0231.py b/test/input/func_w0231.py
@@ -34,5 +34,15 @@
47 
48  class NewStyleB(NewStyleA):
49      """derived new style class"""
50      def __init__(self):
51          super(NewStyleB, self).__init__()
52 +
53 +
54 +class NoInit(object):
55 +    """No __init__ defined"""
56 +
57 +class Init(NoInit):
58 +    """Don't complain for not calling the super __init__"""
59 +
60 +    def __init__(self, arg):
61 +        self.arg = arg