diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2014-07-25 13:07:34 +0200 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2014-07-25 13:07:34 +0200 |
commit | 4449a950ea759331f0840435616be7591fa407a0 (patch) | |
tree | ed2da8e392fe050bea52f169ed3084df53337193 | |
parent | ee26e69c938d62c3fc48cd6848bee35ccce70637 (diff) | |
download | pylint-4449a950ea759331f0840435616be7591fa407a0.tar.gz |
Don't emit hidden-method message when the attribute has been monkey-patched,
you're on your own when you do that
Closes http://www.logilab.org/ticket/36653
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | checkers/classes.py | 10 | ||||
-rw-r--r-- | test/functional/method_hidden.py (renamed from test/input/func_e0205.py) | 6 | ||||
-rw-r--r-- | test/functional/method_hidden.txt | 1 | ||||
-rw-r--r-- | test/messages/func_e0205.txt | 2 | ||||
-rw-r--r-- | test/test_func.py | 2 |
6 files changed, 14 insertions, 10 deletions
@@ -58,6 +58,9 @@ ChangeLog for Pylint * Use the proper mode for pickle when opening and writing the stats file. Closes issue #148. + * Don't emit hidden-method message when the attribute has been + monkey-patched, you're on your own when you do that + 2014-04-30 -- 1.2.1 * Restore the ability to specify the init-hook option via the diff --git a/checkers/classes.py b/checkers/classes.py index 570f7ac..6d9b2df 100644 --- a/checkers/classes.py +++ b/checkers/classes.py @@ -20,7 +20,7 @@ from __future__ import generators import sys import astroid -from astroid import YES, Instance, are_exclusive, AssAttr +from astroid import YES, Instance, are_exclusive, AssAttr, Class from astroid.bases import Generator from pylint.interfaces import IAstroidChecker @@ -341,8 +341,12 @@ a metaclass class method.'} # check if the method is hidden by an attribute try: overridden = klass.instance_attr(node.name)[0] # XXX - args = (overridden.root().name, overridden.fromlineno) - self.add_message('method-hidden', args=args, node=node) + overridden_frame = overridden.frame() + if overridden_frame.type == 'method': + overridden_frame = overridden_frame.parent.frame() + if isinstance(overridden_frame, Class) and klass._is_subtype_of(overridden_frame.qname()): + args = (overridden.root().name, overridden.fromlineno) + self.add_message('method-hidden', args=args, node=node) except astroid.NotFoundError: pass diff --git a/test/input/func_e0205.py b/test/functional/method_hidden.py index 34208f9..0510f55 100644 --- a/test/input/func_e0205.py +++ b/test/functional/method_hidden.py @@ -1,9 +1,7 @@ -# pylint: disable=R0903 +# pylint: disable=too-few-public-methods """check method hidding ancestor attribute """ -__revision__ = '' - class Abcd(object): """dummy""" def __init__(self): @@ -11,7 +9,7 @@ class Abcd(object): class Cdef(Abcd): """dummy""" - def abcd(self): + def abcd(self): # [method-hidden] """test """ print self diff --git a/test/functional/method_hidden.txt b/test/functional/method_hidden.txt new file mode 100644 index 0000000..c15f3bc --- /dev/null +++ b/test/functional/method_hidden.txt @@ -0,0 +1 @@ +method-hidden:12:Cdef.abcd:An attribute defined in functional.method_hidden line 8 hides this method diff --git a/test/messages/func_e0205.txt b/test/messages/func_e0205.txt deleted file mode 100644 index c7402ce..0000000 --- a/test/messages/func_e0205.txt +++ /dev/null @@ -1,2 +0,0 @@ -E: 14:Cdef.abcd: An attribute defined in input.func_e0205 line 10 hides this method - diff --git a/test/test_func.py b/test/test_func.py index 2d573c2..8a0d983 100644 --- a/test/test_func.py +++ b/test/test_func.py @@ -44,7 +44,7 @@ class LintTestNonExistentModuleTC(LintTestUsingModule): class TestTests(testlib.TestCase): """check that all testable messages have been checked""" - PORTED = set(['I0001', 'I0010', 'W0712', 'E1001', 'W1402', 'E1310']) + PORTED = set(['I0001', 'I0010', 'W0712', 'E1001', 'W1402', 'E1310', 'E0202']) @testlib.tag('coverage') def test_exhaustivity(self): |