Challenge supporting custom deepcopy with inheritance

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


In article <mailman.942.1243748839.8015.python-list at python.org>,
Michael H. Goldwasser  <goldwamh at slu.edu> 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
attributes.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

my-python-code-runs-5x-faster-this-month-thanks-to-dumping-$2K-
    on-a-new-machine-ly y'rs  - tim



More information about the Python-list mailing list