[Python-Dev] PEP 362: 4th edition (original) (raw)

Yury Selivanov yselivanov.ml at gmail.com
Tue Jun 19 04:00:57 CEST 2012


On 2012-06-18, at 9:36 PM, Nick Coghlan wrote:

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.

Agree. That's the only thing about the implementation that I really didn't like - deepcopy that's not exactly deep.

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.

So, 'Signature.deepcopy()' -> 'Signature.shallow_copy()'? Or make it private - 'Signature._shallow_copy()'?



More information about the Python-Dev mailing list