[Python-ideas] Minor tweak to PEP 8?

Mike Graham mikegraham at gmail.com
Tue May 10 17:51:33 CEST 2011


On Tue, May 10, 2011 at 10:47 AM, Mike Meyer <mwm at mired.org> wrote:
> PEP eight has an interesting omission in the "Code Layout" section. It
> doesn't say how to indent continuation lines when code is wrapped to
> comply with the line length limits. It has examples, but no textual
> guides. Which means you can do a rock-stupid word warp (with no
> indentation on the continuation lines), point at the resulting mess,
> and say "See? If we follow this part of the PEP, we get really ugly
> code!". Mail doing just that is what prompted this suggestion.
>
> I therefore propose adding a sentence or two to this section,
> something along the lines of:
>
>    The continuation line(s) should be indented to reflect the
>    structure of the statement being continued. This should be at
>    least one space beyond the first open parenthesis that is not
>    closed on the continued line, if present.
>
> Nothing hard and fast, just a requirement to use good sense and the
> minimal indent resulting from doing so.
>
>    <mike

It is not shocking that you can be in technical compliance with PEP8
and have hideous code. PEP8 doesn't attempt to specify every existing
case nor should it, which would be long and pedantic. I'm not sure
anyone has bad enough taste for this omission to be problematic, so
I'm -0 on the the proposal in general.

For this actual rule, I am -1, as I think this is too limiting.
Sometimes the indentation is too far and the best style is

     self.other_thing.some_long_method_name(
        foo,
        barMightBeSortOfLongNaturally,
        baz........

This approach also has the advantage of working well with
variable-width typefaces.

There are too many cases here that it would be silly to enumerate what
style might be best and when.


Mike



More information about the Python-ideas mailing list