[Python-ideas] allow line break at operators

MRAB python at mrabarnett.plus.com
Sun Sep 4 19:59:31 CEST 2011


On 04/09/2011 00:22, Yingjie Lan wrote:
> On 04/09/2011 03:04, MRAB wrote:
>> I think that the rules would be:
>>
>> If a line ends with a colon and the next line is indented, then
>> it's the start of a block, and the following lines which belong to
>> that block have the same indent.
>>
>> If a line doesn't end with a colon but the next line is indented,
>> then it's the start of a continuation, and the following lines
>> which belong to that continuation have the same indent.
>>
>> In both cases there could be blocks nested in blocks and possibly
>> continuations nested in continuations, as well as blocks nested in
>>  continuations and continuations nested in blocks.
>>
>> I'm not sure what the effect would be if you had mis-indented
>> lines. For example, if a line was accidentally indented after a
>> comment, then it would be treated as part of the comment. It's in
>> cases like those that syntax colouring would be helpful. It would
>> be a good idea to use an editor which could indicate in some way
>> when a line is a continuation.
>>
> Thanks, I think that's the rule described in its full glory.
> Currently I am not quite sure of the use case for continuation
> nested in continuation -- it seems to be still a single continuation,
> but it allows for some additional freedom in formatting the continued
> line. Do you have other use cases for that?
>
I don't have a use-case, I was just wondering whether in this:

     first
         second
             third
         fourth

"third" is a continuation, giving this:

     first
         second third
         fourth

which has 2 continuations, leading to this:

     first second third fourth

> For the case of mis-indentation, as demonstrated in your scenario, I
> think it is better that the rule is not applied to a comment
> continued onto the next line. The effect of a '#' only carries to
> the end of a line, if one would like the next line to be a comment,
> just use another '#'. It remains to consider a mis-indentation that
> only involves code lines. However, that is not a new problem, so we
> should not worry (it is like a sunken cost).
>
As well as still limiting a comment to a line, I'd also still limit a
string literal (except a triple-quoted string literal) to a line.



More information about the Python-ideas mailing list