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