Inheritance and delegation problem.

Alex Martelli aleax at aleax.it
Fri Nov 22 05:51:20 EST 2002


Quinet, Joel wrote:

> Hi all,
> 
> I have an object using delegation to another one by replacing __getattr__
> and __setattr__.  It works fine.  now, I have to do it a thread, I have
> added the threading inheritance.
> My problem is the threading.__init__ methode is NOT call apparently due to
> __getattr__ and __setattr__ redefinition.

I think threading.Thread.__init__ IS likely being executed, judging from 
your code below; however, instead of setting attributes on the self object, 
it's going to set them on the classwide __instanceMarketsConfigParser 
thingy, because that's where __setattr__ is shunting the destination of
every assignment of the form self.whatever = anyvalue -- remember that
__setattr__ works for code that's running in methods of the object or
its bases, just as well as it works for outside code.  Same applies to the 
assignments in your own __init__ to self.sortie and self.cond, of course,
and to other attributes of self you're apparently binding in other methods.

The solution might be to find out what attributes DO need to be set on self
rather than on the class-wide thingy, and specialcase them with a simple
if at the start of __setattr__ -- starting with putting a print in the same
__setattr__ may help you get ahold of all the attribute names that do
need to be specialcased that way.


Alex




More information about the Python-list mailing list