On 9/26/2011 6:23 PM, Eric Snow wrote:
As Terry noted, default argument values are sort of read-only. A function's __defaults__ (and __kwdefaults__) is writable and bound to a tuple.
Oh, right, I keep forgetting that. The tuple of defaults in immutable but in current Python, at least, the tuple is replaceable. So a function can indirectly rewrite its defaults as long as it is still bound to its definition name.
The local name that maps to each value in __defaults__ is re-initialized for each call. The proposed nonlocal-from syntax would not reflect these characteristics. Instead it is more of a persistent/static mechanism, just like closures.
For a default that is intended to be permanent and never overshadowed, there is no need to rebind with every call. -- Terry Jan Reedy