Showing content from http://mail.python.org/pipermail/python-dev/attachments/20120607/59900aed/attachment.html below:
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
On 06/07/2012 10:08 AM, Eric Snow wrote:<br>
<blockquote
cite="mid:CALFfu7D1BKN8ivn6zUD_ghk2W2+ZhOaMmvjvMJadmqJq6FxJYg@mail.gmail.com"
type="cite">
<blockquote type="cite">
<pre wrap="">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.
</pre>
</blockquote>
<pre wrap="">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 ...]
</pre>
</blockquote>
<br>
In other words: this is possible but extremely unlikely, and will
only be done knowingly and with deliberate intent by a skilled
practitioner.<br>
<br>
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.<br>
<br>
I am now firmly in the "using __signature__ as a cache is fine,
don't make copies for no reason" camp.<br>
<br>
<br>
<i>/arry</i><br>
</body>
</html>
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4