[Python-ideas] PEP 572: Assignment Expressions (post #4)
Paul Moore
p.f.moore at gmail.com
Wed Apr 11 09:17:08 EDT 2018
On 11 April 2018 at 13:23, Clint Hepner <clint.hepner at gmail.com> wrote:
>> # Even complex expressions can be built up piece by piece
>> y = ((eggs := spam()), (cheese := eggs.method()), cheese[eggs])
> I find the assignments make it difficult to pick out what the final expression looks like.
> The first isn't too bad, but it took me a moment to figure out what y was. Quick: is it
>
> * (a, b, c)
> * (a, (b, c))
> * ((a, b), c)
> * something else
>
> First I though it was (a, b, c), then I thought it was actually ((a, b), c), before
> carefully counting the parentheses showed that I was right the first time.
This is a reasonable concern, IMO. But it comes solidly under the
frequently raised objection "This could be used to create ugly code!".
Writing it as
y = (
(eggs := spam()),
(cheese := eggs.method()),
cheese[eggs]
)
makes it obvious what the structure is.
Paul
More information about the Python-ideas
mailing list