[Python-Dev] PEP 362: 4th edition (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Tue Jun 19 03:36:20 CEST 2012
- Previous message: [Python-Dev] PEP 362: 4th edition
- Next message: [Python-Dev] PEP 362: 4th edition
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [Python-Dev] PEP 362: 4th edition
- Next message: [Python-Dev] PEP 362: 4th edition
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]