
On Wed, Oct 27, 2021 at 10:37 AM Carl Meyer <carl@oddbird.net> wrote:
On Tue, Oct 26, 2021 at 5:29 PM Christopher Barker <pythonchb@gmail.com> wrote:
BTW: was it intentional that this:
In [8]: def fun(x, y=(z:=3)): ...: print(x,y,z) ...: ...:
adds z to the function namespace -- sure seems odd to me.
In [9]: fun(2) 2 3 3
It doesn't. It adds it to the namespace in which the function is defined, which is what you'd expect given when function defaults are currently evaluated (at function definition time).
It's just that if `z` is referenced in the function body and isn't a local, it gets looked up in the enclosing namespace (either as a global, or via closure if the function is nested.)
Oops, I missed seeing that that's actually an early-bound, so my response was on the misinterpretation that the function was written thus: def fun(x, y=>(z:=3)): In which case it *would* add it to the function's namespace. As it currently is, yes, that's added to the same namespace that fun is. ChrisA