[Python-ideas] Allowing comments after line continuations

Serhiy Storchaka storchaka at gmail.com
Fri May 17 11:37:02 CEST 2013


16.05.13 21:41, Bruce Leban написав(ла):
> At Chris Angelico's suggestion, starting another thread on this:
>
> The \ line continuation does not allow comments yet statements that span
> multiple lines may need internal comments. Also spaces after the \ are
> not allowed but trailing spaces are invisible to the reader but not to
> the parser. If you use parenthesis for continuation then you can add
> comments but there are cases where parenthesis don't work, for example,
> before in a with statement, as well as the current discussion of using \
> to make implicit string concatenation explicit. So I propose adopting
> this rule for trailing \ continuation:
>
>     The \ continuation character may be followed by white space and a
>     comment. If a comment is present, there must be at least one
>     whitespace character between the \ and the comment.

I'm strong -1 on "\" line continuation working after comment. This is 
backward incompatible, contr-intuitive (it expected meaning that a 
comment continues on the next line) and error-prone (placing "#" at the 
start of line is used just to temporary exclude some fragment of code).

I'm -0.5 on allowing comments after "\" line continuation. This 
complicates parser (and the one in human mind) and looks contrary to all 
other languages which use "\" for line continuation.

I'm only -0.1 on allowing spaces after "\" line continuation. While "\ " 
causes SyntaxError at compile time it is not an issue. And trailing 
whitespaces should be avoided in any cases, after "\" or not.




More information about the Python-ideas mailing list