On Wed, Oct 27, 2021 at 10:37 AM 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) > > ...: > > ...: > > > > 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.)
Oops, I missed seeing that that's actually an early-bound, so my response was on the misinterpretation that the function was written thus: def fun(x, y=>(z:=3)): In which case it *would* add it to the function's namespace. As it currently is, yes, that's added to the same namespace that fun is. ChrisA _______________________________________________ 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/AFOUMINJNFVBRH5ROFT6USLDV6O6P2PV/ Code of Conduct: http://python.org/psf/codeofconduct/