[Python-ideas] allow line break at operators

Bruce Leban bruce at leapyear.org
Thu Aug 11 22:45:58 CEST 2011


On Thu, Aug 11, 2011 at 12:24 PM, Devin Jeanpierre
<jeanpierreda at gmail.com>wrote:

> Javascript also lets you break lines. For example, this does what you want:
>
>     return 1
>         + 5
>
> Whereas this does not
>
>     return
>         1 + 5
>
> Of course, Python would have no such problem, because you could make both
> cases unambiguous due to the indent.
>
> Devin
>
>
> Note that this is already valid and is not a continuation line:

return 1
+5

Right now you do not need to indent continuation lines. So in order to
disambiguate you would need to enforce indentation for continuations, but
for backward compatibility that would only be required when not using
parentheses or backslashes. Ick. Can blank lines or comment lines appear
between a line and its continuation? That's allowed now as well.

Now allowing line breaks *after* operators would be unambiguous and would
not require new indentation rules. When a line ends with an operator, it's
clearly incomplete (so no fear the reader will think the statement has ended
unlike the above case) and it's a syntax error today:

return 1 +
    5

x = y > 0 and
   y < 10


This code is not valid today without parens or \ regardless of indentation.
I'm +0 on this. I'd use it but does it really add enough convenience?

--- Bruce
Follow me: http://www.twitter.com/Vroo http://www.vroospeak.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110811/31c3eff2/attachment.html>


More information about the Python-list mailing list