[Python-ideas] Allowing comments after line continuations

Steven D'Aprano steve at pearwood.info
Fri May 17 10:59:38 CEST 2013


On 17/05/13 10:04, Terry Jan Reedy wrote:

> To me, having the \ below escape the newline that occurs 60 characters later is 'counter-intuitive'.
>
> a + \ # a very long comment that seems to go on and on forever


You're misreading it, in my (not-so-)humble opinion :-)

The backslash should not be interpreted as an escape, since escapes are only meaningful inside string literals. It should be interpreted as an instruction to the parser, telling it to treat the next line as a continuation of the current line. Anything following the \ needs to be ignored, so the only things which are legal after the backslash should be things which would be ignored anyway, namely whitespace or comments.

Putting the backslash at the end of the comment is ruled out by the requirement that # comments out everything until the end of the line.

Before line continuations within brackets was introduced, I would have cared much more about this issue, but now I'm finding it hard to care. I'm only +0 on allowing comments after \ and +0.5 on allowing whitespace.



-- 
Steven


More information about the Python-ideas mailing list