[Python-Dev] PEP 572: Assignment Expressions (original) (raw)

Nick 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) := funcreturningtuple())[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