I'm sorry Steven, I didn't mean to denigrate your examples.
Please note that I said I was in favour of relaxing the restrictions on the walrus operator. I guess I just meant that using the walrus operator generally adds extra complexity to code and means that more effort is required to read and understand it.  Or, at least, its use often results in fewer lines of code (whether or not that was the primary motive) which means that particular lines of code become more complicated and harder to understand. I try (so far fairly successfully I think 😁) to resist the temptation to use the walrus operator just to save a line of code. (Isn't it "Pythonic" to do one thing and one thing only on each line of code?  I'm sure I read that somewhere.)  I try to only use the walrus when performance matters and I think (or know, from testing) that it will improve performance by avoiding re-evaluating an expression.  Or, possibly, when there is some other compelling reason (sorry, can't think of an example offhand).
Best wishes
Rob Cliffe

On 08/05/2022 17:38, Steven D'Aprano wrote:
On Sun, May 08, 2022 at 04:00:47PM +0100, Rob Cliffe wrote:

Yes, I know unrestricted use of the walrus can lead to obfuscated code
(and some of Steven's examples below might be cited as instances 😁).
They're intended as the simplest, least obfuscatory examples of using
the walrus operator that is not pointless. That is, an example of the
walrus as a sub-expression embedded inside another expression.

If you think my examples are obfuscated, then that is an argument in
favour of keeping the status quo.

I could have given an example like this:

((a, b) := [1, 2])

but there is no good reason to use the walrus operator there, it is not
a sub-expression, and it Just Works if you use the assignment statement
instead.



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

Reply via email to