On Tue, Oct 26, 2021 at 4:37 PM Carl Meyer <c...@oddbird.net> wrote: > On Tue, Oct 26, 2021 at 5:29 PM Christopher Barker <python...@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
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/PU57NRCP253YONQKSTCSUQKB472PHLRB/ Code of Conduct: http://python.org/psf/codeofconduct/