[Python-ideas] allow line break at operators

Ben Finney ben+python at benfinney.id.au
Mon Sep 5 00:39:39 CEST 2011


Ben Finney <ben+python at benfinney.id.au> writes:

> MRAB <python at mrabarnett.plus.com> writes:
>
> > 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.
>
> How many string literals do you count in the following statement? I
> count one:
>
>     raise HoustonWeHaveAProblemError(
>         "Lorem ipsum dolor sit amet,"
>         " consectetur adipiscing elit.")

The Python compiler agrees with me:

    >>> import dis
    >>> def foo():
    ...     raise ValueError(
    ...         "Lorem ipsum dolor sit amet,"
    ...         " consectetur adipiscing elit.")
    ... 
    >>> dis.dis(foo)
      2           0 LOAD_GLOBAL              0 (ValueError) 

      3           3 LOAD_CONST               1 ('Lorem ipsum dolor sit amet, consectetur adipiscing elit.') 
                  6 CALL_FUNCTION            1 
                  9 RAISE_VARARGS            1 
                 12 LOAD_CONST               0 (None) 
                 15 RETURN_VALUE         

So if you do mean “limit a string literal to a line” to cover the above
case, I disagree. I frequently use the fact that a single-quoted string
literal can be broken over multiple lines like the above, to make code
more readable.

-- 
 \     “The Vatican is not a state.… a state must have territory. This |
  `\         is a palace with gardens, about as big as an average golf |
_o__)                         course.” —Geoffrey Robertson, 2010-09-18 |
Ben Finney




More information about the Python-ideas mailing list