On Thu, Dec 2, 2021 at 12:42 PM David Lukeš <dafydd.lu...@gmail.com> wrote: > > > That's an oversimplification: > > > > foo = 42 > > def bar(): > > print(foo) > > foo = 1 > > > > This won't print 42. > > Oh, right. I've run afoul of this in the past, but clearly not often > enough to make it second nature :) Thanks for being helpful! > > I still think nudging people to only refer to previous arguments in > their late-bound defaults is a good idea though, for readability and > intuitiveness.
Oh yes, absolutely. Whether it's legal or not, referring to future arguments will always be frowned upon. > Maybe a good way to enforce it naturally (at least w.r.t. > to arguments without late-bound defaults) would be via a similar syntax > as keyword-only arguments? Something like: > > def foo(bar, *, baz=1, @, qux=[baz]): > ... > That's rather restricting, and it implies that there's a major difference in the way that functions would be defined ("late-bound default keyword-only arguments" would become a brand new type of argument) rather than a small difference in the way a function default is defined. > Now that I look at it, I actually like this bikeshed quite a lot. It > trades some of the flexibility for expliciteness (the @ is very > conspicuous in this position), consistency and predictability, which > feels Pythonic. The @-as-barrier-to-eager-evaluation mnemonic still > works. No potential => footgun. > > But it's late at night and I need to go to bed, so I probably messed > something up again? Not messed up, other than the fact that it's more change than I think this needs. :) 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/SQBJDFUQR3UIKIG6FWWL4FYQT65GYWWT/ Code of Conduct: http://python.org/psf/codeofconduct/