[Python-Dev] Updated PEP 362 (Function Signature Object)
Yury Selivanov
yselivanov.ml at gmail.com
Thu Jun 7 15:32:22 CEST 2012
On 2012-06-07, at 9:28 AM, Michael Foord wrote:
> On 6 Jun 2012, at 18:28, Yury Selivanov wrote:
>> On 2012-06-06, at 1:13 PM, Alexandre Zani wrote:
>> Never copy attributes by hand, always use 'functools.wraps'. It copies
>> '__name__', '__qualname__', and bunch of other attributes to the decorator
>> object.
>>
>> We'll probably extend it to copy __signature__ too; then 'signature(decor(f))'
>> will be the same as 'signature(f)'.
>>
>
> I don't think functools.wraps can copy the signature by default - it's not uncommon to have decorators that modify signatures. A new parameter to functools.wraps defaulting to False?
http://mail.python.org/pipermail/python-dev/2012-June/120021.html
We just won't copy it at all. See the link above.
'functools.wraps' already sets '__wrapped__' reference to the wrapped function,
so we can easily traverse the chain to either first function with __signature__
defined, or to the most inner-decorated function and get a signature for it.
-
Yury
More information about the Python-Dev
mailing list