Re: [Python-Dev] PEP 572: Assignment Expressions

2018年4月18日 03:26:51 -0700

On 18 April 2018 at 11:35, Tim Peters <[email protected]> wrote:
> And, for some reason, I find this even worse:
>
> while ((x, y) := func_returning_tuple())[1] is not None:
> ...
>
> The rub there: I gave `y` a name but can't use it in the test?!
>
> And those are the same kinds of headaches I saw over & over in my own
> "fancier" code: stuff that's already perfectly clear would become
> more obscure instead.
Whereas I think:
 while (s := func_returning_tuple())[1] is not None:
 s = x, y
 ...
compares favourably with the loop-and-a-half version.
It does make the guarantee that "y is not None" harder to spot than it
is in the loop-and-a-half version, though.
Cheers,
Nick.
-- 
Nick Coghlan | [email protected] | Brisbane, Australia
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to