Re: Copying objects and multiple inheritance
- From: "Gabriel Genellina" <gagsl-py2@xxxxxxxxxxxx>
- Date: Wed, 03 Jun 2009 03:57:20 -0300
En Tue, 02 Jun 2009 19:02:47 -0300, Brian Allen Vanderburg II <BrianVanderburg2@xxxxxxx> 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
.
- Prev by Date: Re: FILE object in Python3.0 extension modules
- Next by Date: Re: Using C++ and ctypes together: a vast conspiracy? ;)
- Previous by thread: Python reimport
- Next by thread: Re: Copying objects and multiple inheritance
- Index(es):
Relevant Pages
|