[Python-Dev] Re: [ python-Bugs-416670 ] MatchObjects not deepcopy()able

M.-A. Lemburg mal@lemburg.com
Fri, 27 Apr 2001 12:14:41 +0200


Fredrik Lundh wrote:
> 
> mal wrote:
> > > time to add a __clone__ slot?
> > >
> > > or could someone who knows what he's doing here address
> > > this comment in copy.py:
> > >
> > >     # XXX need to support copy_reg here too...
> >
> > All you have to do is implement the copy protocol (ie. .copy())
> > for the type/class in question.
> 
> cannot find any support for that in the copy module (not in 2.0, at least)
> 
> but another reading revealed support for __copy__ and __deepcopy__
> methods in at least 1.5.2 and later.  intriguing...

You're right... the two methods are named __copy__ and __deepcopy__.
Both should return either copies of the object or simply new reference
in case the object's are immutable.

I've implemented these in mxDateTime and that was all it took to
get the copy module happy (at least in Python 1.5.2).

-- 
Marc-Andre Lemburg
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/