On 25 mars 16:56, Daniel Catarino Biscalchin wrote:
> Hi,
Hi,
> I am trying to correct the bug #9340 by editing the visit_class method
> in file pylint/checkers/classes.py.
Sounds like a good first candidate :)
> I am adding a else statement to the try clause as shown below:
some notes about sending code to the list:
* never use tabulation, this is hardly readable depending on the reader's MUA
* prefered form, when it makes sense, is to send a diff as attachment
> def visit_class(self, node):
> (...)
> if node.type == 'class':
> try:
> attr_list = node.local_attr('__init__')
> meth = attr_list[0] # get the __init__ method
> except astng.NotFoundError:
> self.add_message('W0232', args=node, node=node)
> else: # here begins the verification
> defined_in = meth.parent.frame() # the class in
> which the __init__
> method was defined
> if defined_in != node: # if the __init__ method
> was not defined in
> this class
[snip]
IMO, you should rather change the _check_init method to have a signature like
_check_init(klass_node, init_node=None)
and make it usable as currently and for your case. It should avoid most code
duplication and make your life easier. Also, here are two api hints:
* you should not compare ast nodes using comparison operator, rather using
the 'is' identity operator (as there are now comparison behavior implemented
on ast classes, that's what will be done anyway). Explicit is better than
implicit.
* if you want to check something is declared in the class itself, not in one
of its ancestor, you can check the .locals dictionary directly. I don't mean
you should do that here, that's simply for information.
Also, think to add some tests for this, for instance one for the example in
the ticket and maybe others you may think of. This can easily be done using
code snippets in pylint/test/input and expected messages in
pylint/test/messages,
then by using python test_func.py to run those functionnal tests.
--
Sylvain Thénault LOGILAB, Paris (France)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure: http://www.logilab.fr/services
CubicWeb, the semantic web framework: http://www.cubicweb.org
_______________________________________________
Python-Projects mailing list
[email protected]
http://lists.logilab.org/mailman/listinfo/python-projects