[Python-Dev] PEP 362: 4th edition

Steven D'Aprano steve at pearwood.info
Tue Jun 19 04:02:03 CEST 2012


On Mon, Jun 18, 2012 at 02:09:17PM -0400, Yury Selivanov wrote:

> That's an excerpt from Signature.__deepcopy__:
> 
>      cls = type(self)
>      sig = cls.__new__(cls)
>      sig.parameters = OrderedDict((name, param.__copy__()) \
>                            for name, param in self.parameters.items())
> 
> And Parameter.__copy__:
> 
>         cls = type(self)
>         copy = cls.__new__(cls)
>         copy.__dict__.update(self.__dict__)
>         return copy
> 
> So we don't recursively deepcopy parameters in Signature.__deepcopy__
> (I hope that we don't violate the deepcopy meaning here)


I think you are. I would describe the above as a shallow copy, not a 
deep copy. I expect a deep copy to go *all the way down*, as deep as 
possible.

Even if it makes no practical difference, I think it will be less 
confusing to just describe it as a "copy" rather than a deep copy, 
unless you recursively copy everything all the way down.


-- 
Steven



More information about the Python-Dev mailing list