On Tue, Jun 19, 2012 at 4:09 AM, Yury Selivanov <yselivanov...@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 | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com