Challenge supporting custom deepcopy with inheritance

Aahz aahz at
Wed Jun 3 04:51:19 CEST 2009

In article <mailman.942.1243748839.8015.python-list at>,
Michael H. Goldwasser  <goldwamh at> wrote:
>Assume that class B inherits from class A, and that class A has
>legitimately customized its deepcopy semantics (but in a way that is
>not known to class B).  If we want a deepcopy of B to be defined so
>that relevant state inherited from A is copied as would be done for
>class A, and with B able to control how to deepcopy the extra state
>that it introduces.  I cannot immediately find a general way to
>properly implement the deepcopy of B.
>  [...]
>class A(object):
>    def __init__(self, aTag):
>        self.__aTag = aTag
>        self.__aList = []

IMO, your problem starts right here.  Not only are you using customized
attributes for each class, you're using class-private identifiers.  You
would vastly simplify your work if you switch to single-underscore
Aahz (aahz at           <*>

    on-a-new-machine-ly y'rs  - tim

More information about the Python-list mailing list