
On Tue, Oct 26, 2021 at 4:37 PM 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) ...: ...:
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).
indeed: ----> 1 fun(2) <ipython-input-10-cef0a16457f4> in fun(x, y) 1 def fun(x, y=(z:=3)): ----> 2 z += 1 3 print(x,y,z) 4 5 UnboundLocalError: local variable 'z' referenced before assignment Sorry for the brain fart. Though it does point out the dangers of the walrus operator ... -CHB -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython