don't emit E0202 (attribute hiding a method) on @property methods. Closes #89092

authorSylvain Th?nault <sylvain.thenault@logilab.fr>
changesetb0f72604a2d7
branchdefault
phasepublic
hiddenno
parent revision#c6cbb867a882 InferenceError may be raised when running the next iteration, but we don't want it to propagate
child revision#51fb69c78868 Fix the variables check to not emit false positives for E0602 on {list,generator} comprehension loop variables inside decorators.
files modified by this revision
ChangeLog
checkers/classes.py
test/input/func_noerror_property_affectation_py26.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1331815552 -3600
# Thu Mar 15 13:45:52 2012 +0100
# Node ID b0f72604a2d7fb6b9ee2b0fad726f23c65269641
# Parent c6cbb867a88238fdfd19c8bdf19ebcf4953067fd
don't emit E0202 (attribute hiding a method) on @property methods. Closes #89092

diff --git a/ChangeLog b/ChangeLog
@@ -3,10 +3,11 @@
1 
2  	--
3 
4      * #87192 fix crash when decorators are accessed through more than one dot
5        (for instance @a.b is fine, @a.b.c crash)
6 +    * #89092: don't emit E0202 (attribute hiding a method) on @property methods
7      * fix potential crashes with utils.safe_infer raising InferenceError
8 
9  2011-12-08  --  0.25.1
10      * #81078: Warn if names in  exception handlers clobber overwrite
11        existing names (patch by tmarek@google.com)
diff --git a/checkers/classes.py b/checkers/classes.py
@@ -252,11 +252,21 @@
12                  continue
13              if not isinstance(meth_node, astng.Function):
14                  continue
15              self._check_signature(node, meth_node, 'overridden')
16              break
17 -        # check if the method overload an attribute
18 +        if node.decorators:
19 +            for decorator in node.decorators.nodes:
20 +                if isinstance(decorator, astng.Getattr) and \
21 +                        decorator.attrname in ('getter', 'setter', 'deleter'):
22 +                    # attribute affectation will call this method, not hiding it
23 +                    return
24 +                if isinstance(decorator, astng.Name) and decorator.name == 'property':
25 +                    # attribute affectation will either call a setter or raise
26 +                    # an attribute error, anyway not hiding the function
27 +                    return
28 +        # check if the method is hidden by an attribute
29          try:
30              overridden = klass.instance_attr(node.name)[0] # XXX
31              args = (overridden.root().name, overridden.fromlineno)
32              self.add_message('E0202', args=args, node=node)
33          except astng.NotFoundError:
diff --git a/test/input/func_noerror_property_affectation_py26.py b/test/input/func_noerror_property_affectation_py26.py
@@ -0,0 +1,24 @@
34 +# pylint: disable=R0903
35 +"""
36 +Simple test case for an annoying behavior in pylint.
37 +"""
38 +
39 +__revision__ = 'pouet'
40 +
41 +class Test(object):
42 +    """Smallest test case for reported issue."""
43 +
44 +    def __init__(self):
45 +        self._thing = None
46 +
47 +    @property
48 +    def myattr(self):
49 +        """Getter for myattr"""
50 +        return self._thing
51 +
52 +    @myattr.setter
53 +    def myattr(self, value):
54 +        """Setter for myattr."""
55 +        self._thing = value
56 +
57 +Test().myattr = 'grou'