On 2012-06-18, at 1:35 PM, PJ Eby wrote: > On Fri, Jun 15, 2012 at 5:03 PM, R. David Murray <rdmur...@bitdance.com> > wrote: > On Fri, 15 Jun 2012 22:48:42 +0200, Victor Stinner <victor.stin...@gmail.com> > wrote: > > > 1. Should we keep 'Parameter.implemented' or not. *Please vote* > > -1 to implemented. > > > I still disagree with the deepcopy. I read somewhere that Python > > developers are consenting adult. If someone really want to modify a > > Signature, it would be nice to provide a simple method to copy it. But > > I don't see why it should be copied *by default*. I expect that > > modifying a signature is more rare than just reading a signature. > > The issue isn't "consenting adults", the issue is consistency. > Without the deepcopy, sometimes what you get back from the > inspect function is freely modifiable and sometimes it is not. > That inconsistency is a bad thing. > > 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) > Or, better yet: make signature and parameter objects immutable (along with > the OrderedDict) and the whole problem of modification and copying goes away > altogether. Or is there some reason not mentioned in the PEP why mutability > is necessary? (The PEP provides no rationale at present for making any part > of a signature mutable) The rationale is that sometimes you need to modify signatures. For instance, in decorators. - Yury _______________________________________________ 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