PEP 8 updates on hanging continuation lines, based on discussion from

python-ideas (contributed by Steven Klass).
This commit is contained in:
Barry Warsaw 2011-06-13 12:48:33 -04:00
parent 2b799e8d15
commit e12e762a54
1 changed files with 21 additions and 11 deletions

View File

@ -57,28 +57,38 @@ Code lay-out
For really old code that you don't want to mess up, you can continue to
use 8-space tabs.
Continuation lines should align wrapped elements either vertically using
Python's implicit line joining inside parentheses, brackets and braces,
or using a hanging indent of double your code indention, in which case
there should be no argument on the first line. For example:
Continuation lines should align wrapped elements either vertically using
Python's implicit line joining inside parentheses, brackets and braces, or
using a hanging indent. When using a hanging indent the following
considerations should be applied; there should be no arguments on the
first line and further indentation should be used to clearly distinguish
itself as a continuation line.
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 line
foo = long_function_name(
# More indentation included to distinguish this from the rest.
def long_function_name(
var_one, var_two, var_three,
var_four)
var_four):
print(var_one)
No: # Stuff on first line forbidden
No: # Arguments on first line forbidden when not using vertical alignment
foo = long_function_name(var_one, var_two,
var_three, var_four)
# 2-space hanging indent forbidden
# Further indentation required as indentation is not distinguishable
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
Optional:
# Extra indentation is not necessary.
foo = long_function_name(
var_one, var_two, var_three,
var_four)
var_one, var_two,
var_three, var_four)
Tabs or Spaces?