
Oct. 26, 2021
11:37 p.m.
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.) Carl