[Python-Dev] PEP 362: 4th edition

Nick Coghlan ncoghlan at gmail.com
Tue Jun 19 03:36:20 CEST 2012


On Tue, Jun 19, 2012 at 4:09 AM, Yury Selivanov <yselivanov.ml at gmail.com> wrote:
> On 2012年06月18日, at 1:35 PM, PJ Eby wrote:
>> Then just copy the signature itself; as currently written, this is going to copy the annotation objects, which could produce weird side-effects from introspection.  Using deepcopy seems like overkill when all that's needed is a new Signature instance with a fresh OrderedDict.
>> 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)

In my opinion, It's better to redefine what you mean by a shallow copy
(making it a bit deeper than just the direct attributes) rather than
making a so-called deep copy shallower.
So keep the current copying semantics for Signature objects (i.e.
creating new copies of the Parameter objects as well), but call it a
shallow copy rather than a deep copy. Make it clear in the
documentation that any defaults and annotations are still shared with
the underlying callable.
Cheers,
Nick.
-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /