Copying objects and multiple inheritance

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Jun 3 02:57:20 EDT 2009


En Tue, 02 Jun 2009 19:02:47 -0300, Brian Allen Vanderburg II  
<BrianVanderburg2 at aim.com> escribió:

> What is the best way to copy an object that has multiple inheritance  
> with the copy module.  Particularly, some of the instances in the  
> hierarchy

("...some of the classes in...", I presume?)

> use the __copy__ method to create a copy (because even for shallow  
> copies they need some information  updated a little differently), so how  
> can I make sure all the information is copied as it is supposed to be  
> even for the base classes that have special requirements.

If you don't control all the clases involved, there is little hope for a  
method like __copy__ to work at all... All classes must be written with  
cooperation in mind, using super() the "right" way. See "Python's Super  
Considered Harmful" [1] and "Things to Know About Python Super" [2][3][4]

That said, and since multiple inheritance is the heart of the problem,  
maybe you can redesign your solution *without* using MI? Perhaps using  
delegation instead?

[1] http://fuhm.net/super-harmful/
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=236275
[3] http://www.artima.com/weblogs/viewpost.jsp?thread=236278
[4] http://www.artima.com/weblogs/viewpost.jsp?thread=237121

-- 
Gabriel Genellina




More information about the Python-list mailing list