deepcopy does not work for A subclassed list

MRAB python at mrabarnett.plus.com
Fri Oct 7 16:37:00 EDT 2011


On 07/10/2011 20:29, txismis unzetabarrenetxeagoikolea wrote:
> This is the issue
>
> I have created a mylist class by subclassing a List, added several
> attributes to mylIst , and overrided the append method which takes into
> account one of the new attributes.
>
> mylist class is functional and works as I planned, but when I try to
> deepcopy objects from mylist I received errors because the attribute has
> not been copied and the override append raise an error.
>
> When I want to deepcopy one object from mylist the algorithm does not
> take into account the attributes I created; ergo, I have some errors
> from the copy module
>
> I can use pickle to dump and load objects from my subclass with no errors.
>
> Any ideas about how to make the copy module to behave as expected.
>
The documentation talks about defining a "__deepcopy__" method.



More information about the Python-list mailing list