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.

That is:

x = y + \   # comment allowed here

with a as x, \   # comment here may be useful
     b as y, \   # or here
     c as z: \   # or here

x = y +     # syntax error

Two reasons for requiring a space after the backslash:

(1) make the backslash more likely to stand out visually (and we can't require a space before it)

(2) \# looks like it might be an escape sequence of some sort while I don't think \ # does, making this friendlier to readers.

I'm not passionate about that detail if the rest of the proposal flies.

--- Bruce
Latest blog post: Alice's Puzzle Page
Learn how hackers think: