summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Thénault <sylvain.thenault@logilab.fr>2012-03-15 13:45:52 +0100
committerSylvain Thénault <sylvain.thenault@logilab.fr>2012-03-15 13:45:52 +0100
commitf6ad8e26b9586d280d42581b721ce2d3e9124b1e (patch)
treec4c7f7b42b052917bb02fd4f84599a6b9e9d7bba
parentd1ae21960ac1b39f9b6100ac5c790af30236edac (diff)
downloadpylint-git-f6ad8e26b9586d280d42581b721ce2d3e9124b1e.tar.gz
don't emit E0202 (attribute hiding a method) on @property methods. Closes #89092
-rw-r--r--ChangeLog1
-rw-r--r--checkers/classes.py12
-rw-r--r--test/input/func_noerror_property_affectation_py26.py24
3 files changed, 36 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index e8f1da82e..6ebe87919 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@ ChangeLog for PyLint
* #87192 fix crash when decorators are accessed through more than one dot
(for instance @a.b is fine, @a.b.c crash)
+ * #89092: don't emit E0202 (attribute hiding a method) on @property methods
* fix potential crashes with utils.safe_infer raising InferenceError
2011-12-08 -- 0.25.1
diff --git a/checkers/classes.py b/checkers/classes.py
index 60d20b6c9..847646e0d 100644
--- a/checkers/classes.py
+++ b/checkers/classes.py
@@ -254,7 +254,17 @@ a class method.'}
continue
self._check_signature(node, meth_node, 'overridden')
break
- # check if the method overload an attribute
+ if node.decorators:
+ for decorator in node.decorators.nodes:
+ if isinstance(decorator, astng.Getattr) and \
+ decorator.attrname in ('getter', 'setter', 'deleter'):
+ # attribute affectation will call this method, not hiding it
+ return
+ if isinstance(decorator, astng.Name) and decorator.name == 'property':
+ # attribute affectation will either call a setter or raise
+ # an attribute error, anyway not hiding the function
+ return
+ # check if the method is hidden by an attribute
try:
overridden = klass.instance_attr(node.name)[0] # XXX
args = (overridden.root().name, overridden.fromlineno)
diff --git a/test/input/func_noerror_property_affectation_py26.py b/test/input/func_noerror_property_affectation_py26.py
new file mode 100644
index 000000000..d91f455dd
--- /dev/null
+++ b/test/input/func_noerror_property_affectation_py26.py
@@ -0,0 +1,24 @@
+# pylint: disable=R0903
+"""
+Simple test case for an annoying behavior in pylint.
+"""
+
+__revision__ = 'pouet'
+
+class Test(object):
+ """Smallest test case for reported issue."""
+
+ def __init__(self):
+ self._thing = None
+
+ @property
+ def myattr(self):
+ """Getter for myattr"""
+ return self._thing
+
+ @myattr.setter
+ def myattr(self, value):
+ """Setter for myattr."""
+ self._thing = value
+
+Test().myattr = 'grou'