[Python-Dev] pep 362 - 5th edition (original) (raw)
Yury Selivanov yselivanov.ml at gmail.com
Wed Jun 20 05:28:29 CEST 2012
- Previous message: [Python-Dev] pep 362 - 5th edition
- Next message: [Python-Dev] pep 362 - 5th edition
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2012-06-19, at 11:24 PM, Nick Coghlan wrote:
On Wed, Jun 20, 2012 at 12:36 PM, Yury Selivanov <yselivanov.ml at gmail.com> wrote:
On 2012-06-19, at 9:22 PM, Yury Selivanov wrote:
On 2012-06-19, at 8:39 PM, Nick Coghlan wrote:
7. The idea of immutable Signature objects does highlight an annoyance with the "attribute may be missing" style APIs. To actually duplicate a signature correctly, including its return annotation (and assuming the attribute is renamed), you would have to do something like:
try: note = {"annotation": oldsig.annotation} except AttributeError: note = {} newsig = Signature(oldsig.parameters[1:], **note) BTW, we don't have slices for OrderedDict. Since the slice object is not hashable, we can implement it safely. I can create an issue (and draft implementation), as I think it'd be quite a useful feature. No need, my example was just wrong, it should be: newsig = Signature(oldsig.parameters.values()[1:]) The constructor accepts an iterable of Parameter objects rather than a mapping.
That's the code I've ended up with:
sig = signature(obj.__func__)
return Signature(OrderedDict(tuple(sig.parameters.items())[1:]),
**sig.optional)
Still looks better than creating implicit & explicit copies ;)
As for slices support in OrderedDict -- it would return values, so it won't solve the problem anyways.
- Yury
- Previous message: [Python-Dev] pep 362 - 5th edition
- Next message: [Python-Dev] pep 362 - 5th edition
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]