[Python-ideas] Silent bugs - was Re: PEP8 operator must come before line break

Chris Angelico rosuav at gmail.com
Thu Apr 14 16:04:12 EDT 2016


On Fri, Apr 15, 2016 at 5:41 AM, Erik <python at lucidity.plus.com> wrote:
> On 14/04/16 20:22, Serhiy Storchaka wrote:
>>
>> An argument for operators "+" and "-":
>>
>>      result = expr1 +
>>      expr2
>>
>> is syntax error, while
>>
>>      result = expr1
>>      + expr2
>>
>> is silent bug.
>
>
> Interesting. But that bug potentially exists regardless of what PEP8 says.
>

Yes, but if you encourage people to spell it the first way, you can't
accidentally leave part of your expression out of your result.

However, I wouldn't write it like *either* of those. To me, the options are:

result = expr1 +
    expr2

and

result = expr1
    + expr 2

And either of those would give an immediate IndentationError without
the parentheses. So indenting the continuation is even better than
choosing where to place the binary operator.

ChrisA


More information about the Python-ideas mailing list