On 18 April 2018 at 11:35, Tim Peters <tim.pet...@gmail.com> 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   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
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