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) > ...: > ...: > > 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 _______________________________________________ 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/STHTTDVN5D6A5LIBR7PTUOXMEQD2GDXT/ Code of Conduct: http://python.org/psf/codeofconduct/