[Python-ideas] Allowing comments after line continuations

David Mertz mertz at gnosis.cx
Thu May 16 21:18:46 CEST 2013


+1000


On Thu, May 16, 2013 at 12:11 PM, MRAB <python at mrabarnett.plus.com> wrote:

> On 16/05/2013 19:41, Bruce Leban wrote:
>
>> 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
>>          z
>>
>>     with a as x, \   # comment here may be useful
>>           b as y, \   # or here
>>           c as z: \   # or here
>>          pass
>>
>>     x = y +     # syntax error
>>          z
>>
>> 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.
>>
>>  You don't get escape sequences outside strings, so I'd be inclined not
> to insist that it be followed by a space, although it could be
> suggested as good style.
>
>
>  I'm not passionate about that detail if the rest of the proposal flies.
>>
>>  +1
>
> ______________________________**_________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/**mailman/listinfo/python-ideas<http://mail.python.org/mailman/listinfo/python-ideas>
>



-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130516/c1cf6386/attachment.html>


More information about the Python-ideas mailing list