[Python-Dev] Updated PEP 362 (Function Signature Object)

Larry Hastings larry at hastings.org
Thu Jun 7 20:34:49 CEST 2012


On 06/07/2012 10:08 AM, Eric Snow wrote:
>> I'm missing something here.  Can you give me an example of modifying an
>> existing function object such that its Signature would change?  Decorators
>> implementing a closure with a different signature don't count--they return a
>> new function object.
> I doubt there are any but corner cases to demonstrate here.  I'd don't
> presume to say what use there may be in changing a function's state.
> However, the fact is that a change to any of the following would cause
> a cached __signature__ to be out of sync:
>
> * f.__annotations__
> * f.__closure__
> * f.__code__
> [... other dunder attributes elided ...]

In other words: this is possible but extremely unlikely, and will only 
be done knowingly and with deliberate intent by a skilled practitioner.

I think it's reasonable to declare that, if you're monkeying around with 
dunder attributes on a function, it's up to you to clear the 
f.__signature__ cache if it's set.  Like Spiderman's uncle Cliff 
Robertson said: with great power comes great responsibility.

I am now firmly in the "using __signature__ as a cache is fine, don't 
make copies for no reason" camp.


//arry/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20120607/59900aed/attachment.html>


More information about the Python-Dev mailing list