better message for E0202 (closes #77237)

this also ease treatment: don't try to search parent frame (ie belonging class) which may be hazardous, simply use the assignment node.

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changesetc30b0473b310
branchdefault
phasepublic
hiddenno
parent revision#f31cbe94d9c6 closes #76920: don't crash in preprocess_option if some looked option has no value
child revision#edc4c99cbd33 closes #73941: HTML reports badly formatted since col_offset addition, which was only partially added to the report
files modified by this revision
ChangeLog
checkers/classes.py
test/messages/func_e0205.txt
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1317632298 -7200
# Mon Oct 03 10:58:18 2011 +0200
# Node ID c30b0473b310451263ca03f93a698441eb54d48c
# Parent f31cbe94d9c6c1e50b30fadc0a88b92edc2b227f
better message for E0202 (closes #77237)

this also ease treatment: don't try to search parent frame (ie belonging class) which may
be hazardous, simply use the assignment node.

diff --git a/ChangeLog b/ChangeLog
@@ -14,10 +14,12 @@
1      * #74747: crash occurs when lookup up a special attribute in class scope
2        (patch by google)
3 
4      * #76920: crash if on eg "pylint --rcfile"(patch by Torsten Marek)
5 
6 +    * #77237: warning for E0202 may be very misleading
7 +
8 
9  2011-07-18  --  0.24.0
10      * #69738: add regular expressions support for "generated-members"
11 
12      * ids of logging and string_format checkers have been changed:
diff --git a/checkers/classes.py b/checkers/classes.py
@@ -1,6 +1,6 @@
13 -# Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE).
14 +# Copyright (c) 2003-2011 LOGILAB S.A. (Paris, FRANCE).
15  # http://www.logilab.fr/ -- mailto:contact@logilab.fr
16  #
17  # This program is free software; you can redistribute it and/or modify it under
18  # the terms of the GNU General Public License as published by the Free Software
19  # Foundation; either version 2 of the License, or (at your option) any later
@@ -39,13 +39,14 @@
20      'F0202': ('Unable to check methods signature (%s / %s)',
21                'Used when PyLint has been unable to check methods signature \
22                compatibility for an unexpected reason. Please report this kind \
23                if you don\'t make sense of it.'),
24 
25 -    'E0202': ('An attribute inherited from %s hide this method',
26 -              'Used when a class defines a method which is hidden by an \
27 -              instance attribute from an ancestor class.'),
28 +    'E0202': ('An attribute affected in %s line %s hide this method',
29 +              'Used when a class defines a method which is hidden by an '
30 +              'instance attribute from an ancestor class or set by some '
31 +              'client code.'),
32      'E0203': ('Access to member %r before its definition line %s',
33                'Used when an instance member is accessed before it\'s actually\
34                assigned.'),
35      'W0201': ('Attribute %r defined outside __init__',
36                'Used when an instance attribute is defined outside the __init__\
@@ -254,15 +255,12 @@
37              self._check_signature(node, meth_node, 'overridden')
38              break
39          # check if the method overload an attribute
40          try:
41              overridden = klass.instance_attr(node.name)[0] # XXX
42 -            # we may be unable to get owner class if this is a monkey
43 -            # patched method
44 -            while overridden.parent and not isinstance(overridden, astng.Class):
45 -                overridden = overridden.parent.frame()
46 -            self.add_message('E0202', args=overridden.name, node=node)
47 +            args = (overridden.root().name, overridden.fromlineno)
48 +            self.add_message('E0202', args=args, node=node)
49          except astng.NotFoundError:
50              pass
51 
52      def leave_function(self, node):
53          """on method node, check if this method couldn't be a function
diff --git a/test/messages/func_e0205.txt b/test/messages/func_e0205.txt
@@ -1,2 +1,2 @@
54 -E: 14:Cdef.abcd: An attribute inherited from Abcd hide this method
55 +E: 14:Cdef.abcd: An attribute affected in input.func_e0205 line 10 hide this method
56