[Python-Dev] PEP 572: Assignment Expressions (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Wed Apr 18 06:23:39 EDT 2018
- Previous message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Next message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Next message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]