deepcopy does not work for A subclassed list
Terry Reedy
tjreedy at udel.edu
Fri Oct 7 19:35:19 EDT 2011
On 10/7/2011 4:37 PM, MRAB wrote:
> On 07/10/2011 20:29, txismis unzetabarrenetxeagoikolea wrote:
>> Any ideas about how to make the copy module to behave as expected.
>>
> The documentation talks about defining a "__deepcopy__" method.
Specifically, in the copy module doc
"In order for a class to define its own copy implementation, it can
define special methods __copy__() and __deepcopy__(). The former is
called to implement the shallow copy operation; no additional arguments
are passed. The latter is called to implement the deep copy operation;
it is passed one argument, the memo dictionary. If the __deepcopy__()
implementation needs to make a deep copy of a component, it should call
the deepcopy() function with the component as first argument and the
memo dictionary as second argument."
All the possible customization methods are discussed in Language
Reference 3.3. Special method names
--
Terry Jan Reedy
More information about the Python-list
mailing list