Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8068 > unrolled thread

PEP 8 and indentation of continuation lines

Started byJohn Yeung <gallium.arsenide@gmail.com>
First post2011-06-20 21:11 -0700
Last post2011-06-21 15:39 +1000
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  PEP 8 and indentation of continuation lines John Yeung <gallium.arsenide@gmail.com> - 2011-06-20 21:11 -0700
    Re: PEP 8 and indentation of continuation lines Ben Finney <ben+python@benfinney.id.au> - 2011-06-21 15:22 +1000
      Re: PEP 8 and indentation of continuation lines Ben Finney <ben+python@benfinney.id.au> - 2011-06-21 15:39 +1000

#8068 — PEP 8 and indentation of continuation lines

FromJohn Yeung <gallium.arsenide@gmail.com>
Date2011-06-20 21:11 -0700
SubjectPEP 8 and indentation of continuation lines
Message-ID<eb561969-9ab7-4da5-8be9-dacbc9409bc6@t9g2000vbv.googlegroups.com>
Lurking on python-dev, I noticed a thread early this month (starting
June 2) about possible additions to PEP 8 covering indentation of
continuation lines.  The recommendation was to double-indent
continuation lines which are about to introduce a new suite, unless
you are going to base your indentation on the opening paren.  Examples
from that thread include

def some_really_long_function_name(
        an_argument,
        another_argument,
        and_a_third_argument):
    foo()

if some_really_long_function_name(
        an_argument,
        another_argument,
        and_a_third_argument):
    foo()

So last week PEP 8 was updated to reflect this.  All fine and good.  I
happen to prefer this style myself.  But there remains an example
further down (left over from earlier incarnations of PEP 8) which
might go against this:

if (width == 0 and height == 0 and
    color == 'red' and emphasis == 'strong' or
    highlight > 100):
    raise ValueError("sorry, you lose")

The above satisfies the "opening paren" alignment, but due to the
length of the keyword, the suite is obscured.  For this example,
should PEP 8 use the double-indentation for the continuation lines?
(There was also discussion of this in a comp.lang.python thread last
year, subject: if, continuation and indentation, started May 27.)

John Y.

[toc] | [next] | [standalone]


#8072

FromBen Finney <ben+python@benfinney.id.au>
Date2011-06-21 15:22 +1000
Message-ID<87k4cfpxlf.fsf@benfinney.id.au>
In reply to#8068
John Yeung <gallium.arsenide@gmail.com> writes:

> So last week PEP 8 was updated to reflect this. All fine and good. I
> happen to prefer this style myself. But there remains an example
> further down (left over from earlier incarnations of PEP 8) which
> might go against this:
>
> if (width == 0 and height == 0 and
>     color == 'red' and emphasis == 'strong' or
>     highlight > 100):
>     raise ValueError("sorry, you lose")
>
> The above satisfies the "opening paren" alignment, but due to the
> length of the keyword, the suite is obscured.  For this example,
> should PEP 8 use the double-indentation for the continuation lines?

I wrote some code just today that needs the above issue addressed. I did
it like this::

    if (
          width == 0 and height == 0 and
          color == 'red' and emphasis == 'strong' or
          highlight > 100):
      raise ValueError("sorry, you lose")

-- 
 \                         “I'm a great lover, I'll bet.” —Emo Philips |
  `\                                                                   |
_o__)                                                                  |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#8074

FromBen Finney <ben+python@benfinney.id.au>
Date2011-06-21 15:39 +1000
Message-ID<87fwn3pwua.fsf@benfinney.id.au>
In reply to#8072
Ben Finney <ben+python@benfinney.id.au> writes:

> John Yeung <gallium.arsenide@gmail.com> writes:
>
> > So last week PEP 8 was updated to reflect this. All fine and good. I
> > happen to prefer this style myself. But there remains an example
> > further down (left over from earlier incarnations of PEP 8) which
> > might go against this:
> >
> > if (width == 0 and height == 0 and
> >     color == 'red' and emphasis == 'strong' or
> >     highlight > 100):
> >     raise ValueError("sorry, you lose")
> >
> > The above satisfies the "opening paren" alignment, but due to the
> > length of the keyword, the suite is obscured.  For this example,
> > should PEP 8 use the double-indentation for the continuation lines?
>
> I wrote some code just today that needs the above issue addressed. I
> did it like this::

The formatting was messed up. Since the whitespace is the whole point
here, this is what I intended to send::

    if (
            width == 0 and height == 0 and
            color == 'red' and emphasis == 'strong' or
            highlight > 100):
        raise ValueError("sorry, you lose")

-- 
 \      “The process by which banks create money is so simple that the |
  `\     mind is repelled.” —John Kenneth Galbraith, _Money: Whence It |
_o__)                                       Came, Where It Went_, 1975 |
Ben Finney

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web