A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2018-April/152758.html below:

[Python-Dev] PEP 572: Assignment Expressions

[Python-Dev] PEP 572: Assignment Expressions [Python-Dev] PEP 572: Assignment ExpressionsNick Coghlan ncoghlan at gmail.com
Wed Apr 18 06:23:39 EDT 2018
On 18 April 2018 at 11:35, Tim Peters <tim.peters at 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   |   ncoghlan at gmail.com   |   Brisbane, Australia
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4