[Python-checkins] [Python-Dev] peps: Add rules for indenting continuation lines.

R. David Murray rdmurray at bitdance.com
Thu Jun 2 21:07:06 CEST 2011


On Thu, 02 Jun 2011 14:19:00 -0400, Barry Warsaw <barry at python.org> wrote:
> On Jun 02, 2011, at 08:09 PM, guido.van.rossum wrote:
> >+    Yes:  # Aligned with opening delimiter
> >+          foo = long_function_name(var_one, var_two,
> >+                                   var_three, var_four)
> >+
> >+          # Double code indention for hanging indent; nothing on first li=
> ne
> >+          foo = long_function_name(
> >+                  var_one, var_two, var_three,
> >+                  var_four)
> >+
> >+    No:   # Stuff on first line forbidden
> >+          foo = long_function_name(var_one, var_two,
> >+              var_three, var_four)
> >+
> >+          # 2-space hanging indent forbidden
> >+          foo = long_function_name(
> >+            var_one, var_two, var_three,
> >+            var_four)
> 
> As I mentioned to Guido, I'm not sure where the double-indent recommendation
> comes from, but it's entirely possible I missed that discussion.  I agree with
> the recommendations, but think a single-indentation level looks fine.  E.g.

Personally, I use "enough" indentation.  Sometimes that is a single
indentation level, but sometimes it is more.  Two spaces is definitely
right out, though :)

The place where a single indentation level is *not* enough is when the
line being indented is the statement starting a suite:

    for x in long_function_name(
        var_one, var_two, var_three):
        print x

    vs

    for x in long_function_name(
            var_one, var_two, var_three):
        print x

That's a case where I'd be likely to use even more than two indentation
levels.  Usually, though, I try to refactor the statement so it fits
on one line.

--
R. David Murray           http://www.bitdance.com


More information about the Python-checkins mailing list