On Wed, Nov 10, 2021 at 6:02 PM Christopher Barker <python...@gmail.com> wrote:
>
> On Mon, Nov 8, 2021 at 11:22 PM Rob Cliffe via Python-ideas 
> <python-ideas@python.org> wrote:
>>
>> I have more than once advocated
>>      x:=default
>> (and there is no clash with the walrus operator, even if others have
>> said/implied that there is).
>
>
> not a clash, but you could have a walrus in the default expression, which 
> could be pretty visually confusing. On the other hand, maybe that's a really 
> bad idea anyway. And otherwise I like it.
>
> BTW, => would have a similar problem if it's adopted as a shorter way to 
> spell lambda. And that would be worse, as putting a lambda in a default 
> depression might be good style in some cases :-)
>

In both cases, it would be confusing to a human, but not technically
ambiguous. I'm not sure how important that will be - neither case
seems particularly common, and if you do need to do it, you can always
parenthesize a bit.

Using the walrus operator in a default expression would be VERY weird
(why on earth would you be assigning in the middle of default arg
handling?!?), but if you really want it, sure!

Using a hypothetical lambda function in an argument default wouldn't
be unreasonable, but the number of times you'd also need that to be
late-bound would be extremely few. Normally you'd get something like
this:

def merge_objects(stuff, key=lambda item: item.id): ...

where the default key function doesn't need to refer to any of the
other parameters, so it can be early-bound. But maybe you want to be
able to do something weird like:

def merge_objects(stuff, idfield="id", match=>lambda item: item[idfield]): ...

in which case that might end up being spelled "match=>item =>
item[idfield]", but aside from that, it's unlikely to cause major
problems.

(For the most part, lambda functions will be used when *calling* that
sort of function, and there's no ambiguity there, since you'll only
ever use "=" for keyword arguments, or nothing at all for positional.)

My view on this is: All variants of spelling that involve changes to
the equals sign are one group of options, and it's my favoured group
(whether it's "=>", ":=", "=:", etc). All variants that involve
adornments elsewhere ("@var=dflt", "var=@dflt@", "var=`dflt`") are
less appealing to me. The ":=" syntax is listed in the current PEP,
but I'll adjust the wording of things a bit to make that group
clearer.

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

Reply via email to