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/
_______________________________________________
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

Reply via email to