PEP8 and 4 spaces

Tim Chase python.list at tim.thechases.com
Sat Jul 5 01:35:34 CEST 2014


On 2014-07-05 11:17, Gregory Ewing wrote:
> > PEP8 suggests using this style of method invocation:
> > 
> >     obj.method(foo,
> >                bar,
> >                baz)
> > 
> > which is an effect impossible to do correctly with tabs alone.  
> 
> Yes, PEP 8 is self-contradictory in that regard.
> I also happen to think that recommendation is insane
> for other reasons as well, and cheerfully ignore it.

To be fair, in the same section[1] that example is given, it also
suggests

# More indentation included to distinguish this from the rest.
def long_function_name(
        var_one, var_two, var_three,
        var_four):
    print(var_one)

# Hanging indents should add a level.
foo = long_function_name(
    var_one, var_two,
    var_three, var_four)

both of which can be done with arbitrary indentation without the need
to mix tabs+spaces or use a non-integer multiple of
indentation-spaces.  I just use these two in all instances and (as
you, Greg, advise), "cheerfully ignore [the first form]"


The only time I intentionally violate the "don't do these" section

"""
# Arguments on first line forbidden when not using vertical alignment.
foo = long_function_name(var_one, var_two,
    var_three, var_four)
"""

is when defining options in optparse:

  parser.add_option("-v", "--verbose",
    help="be prolix",
    action="store_true",
    dest="verbose",
    default=False,
    )

as I find that a little easier to read when I'm scanning large blocks
of parser.add_option(...) calls, having the option stick out to the
right.

-tkc

[1] http://legacy.python.org/dev/peps/pep-0008/#indentation







More information about the Python-list mailing list