[Python-ideas] PEP 572: about the operator precedence of :=
p.f.moore at gmail.com
Thu May 10 12:49:49 EDT 2018
On 10 May 2018 at 17:38, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 05/10/2018 09:29 AM, M.-A. Lemburg wrote:
>> On 10.05.2018 15:57, Guido van Rossum wrote:
>>> On Thu, May 10, 2018 at 5:04 AM, M.-A. Lemburg wrote:
>>>> To a (former Pascal) programmer, a := 1 doesn't read like an
>>>> operator. It's an assignment expression. If embedded expressions
>>>> is where Python is heading, it should be made very clear where
>>>> the embedded expression starts and where it ends on a line.
>>> The rules we've arrived at are about as straightforward as it gets: the
>>> of `:=` ends at the nearest comma or close parenthesis/bracket/brace.
>> That may be easy for a computer to parse, but it's not for
>> a programmer. It would be better to contain such expressions
>> inside a safe container which is clearly visible to a human
>> ohoh = a := (1, 2, 3), 4, a * 2
> I have no problem reading that.
>> aha = ((a := (1, 2, 3)), 4, a * 2)
> The extra parens are unneeded line noise (at least for me).
I found the version with extra parens *harder* to read. Although I
will admit neither is particularly easy to read (not surprising as
it's an artificial example intended to prove a point, not a real world
use case) and in practice I'd write
a = 1, 2, 3
ohoh = a, 4, a * 2
Look ma, no parens!
More information about the Python-ideas