On Sat, Dec 4, 2021 at 11:25 PM Chris Angelico <ros...@gmail.com> wrote:
> > def add(a, b): > > return a+b > > How could you write that differently with your PEP > > I wouldn't. There are no default arguments, and nothing needs to be > changed. > I do recognize that I *could* call that with named arguments. I also recognize that the long post I wrote in the bath from my tablet is rife with embarrassing typos :-). Technically, I'd need `def add(a, b, /)` to be positional-only. But in practice, almost everyone who writes or calls a function like that passes by position. I'm not sure that I've *ever* actually used the explicit positional-only `/` other than to try it out. If I have, it was rare enough that I had to look it up then, as I did just now. Actually PEP 671 applies identically to arguments passed by name or > position, and identically to keyword-only, positional-or-keyword, and > positional-only parameters. > > >>> def f(a=>[], /, b=>{}, *, c=>len(a)+len(b)): > ... print(a, b, c) > Wow! That's an even bigger teaching nightmare than I envisioned in my prior post. Nine (3x3) different kinds of parameters is already too big of a cognitive burden. Doubling that to 18 kinds makes me shudder. I admit I sort of blocked out the positional-only defaults thing. I understand that it's needed to emulate some of the builtin or standard library functions, but I would avoid allowing that in code review... specifically because of the burden on future readers of the code. -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.
_______________________________________________ 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/GH7TDMDRW3KNAXY5S4DOAXHCJPIL6EEM/ Code of Conduct: http://python.org/psf/codeofconduct/