Sorry, I forgot a 'object' inside class A declaration. The correct code is:

class A(object):
    pass

2011/3/25 Daniel Catarino Biscalchin <[email protected]>:
> Hi,
>
> I am trying to correct the bug #9340 by editing the visit_class method
> in file pylint/checkers/classes.py.
> I am adding a else statement to the try clause as shown below:
>
>    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
>                                        to_call = []
>                                        for base_node in 
> node.ancestors(recurs=False):
>                                                if base_node != defined_in:
>                                                        try:
>                                                                
> base_node.local_attr('__init__')
>                                                        except 
> astng.NotFoundError:
>                                                                continue
>                                                        else:
>                                                                
> to_call.append(base_node) # the base_node has a __init__
> method not inherited (then, not called)
>                                        for base_node in to_call:
>                                                self.add_message('W0231', 
> args=base_node.name, node=node)
>
> Basically, what I am trying to do is adding a W0231 message for each
> base class which has a not inherited __init__ method.
> The problem is that when I execute using the input shown below,
> defined_in is assigned with the class object. But executing this code
> results in "B constructor". Since the method executed came from B, is
> that behavior correct?
> I've noticed that inverting the base classes in the class C
> declaration makes it work properly.
>
> class A():
>    pass
>
> class B(object):
>    def __init__(self):
>        print "B constructor"
>
> class C(A, B):
>    pass
>
> C()
>
_______________________________________________
Python-Projects mailing list
[email protected]
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to