PEP 8 updates on hanging continuation lines, based on discussion from
python-ideas (contributed by Steven Klass).
This commit is contained in:
parent
2b799e8d15
commit
e12e762a54
30
pep-0008.txt
30
pep-0008.txt
|
@ -58,27 +58,37 @@ Code lay-out
|
||||||
use 8-space tabs.
|
use 8-space tabs.
|
||||||
|
|
||||||
Continuation lines should align wrapped elements either vertically using
|
Continuation lines should align wrapped elements either vertically using
|
||||||
Python's implicit line joining inside parentheses, brackets and braces,
|
Python's implicit line joining inside parentheses, brackets and braces, or
|
||||||
or using a hanging indent of double your code indention, in which case
|
using a hanging indent. When using a hanging indent the following
|
||||||
there should be no argument on the first line. For example:
|
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
|
Yes: # Aligned with opening delimiter
|
||||||
foo = long_function_name(var_one, var_two,
|
foo = long_function_name(var_one, var_two,
|
||||||
var_three, var_four)
|
var_three, var_four)
|
||||||
|
|
||||||
# Double code indention for hanging indent; nothing on first line
|
# More indentation included to distinguish this from the rest.
|
||||||
foo = long_function_name(
|
def long_function_name(
|
||||||
var_one, var_two, var_three,
|
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,
|
foo = long_function_name(var_one, var_two,
|
||||||
var_three, var_four)
|
var_three, var_four)
|
||||||
|
|
||||||
# 2-space hanging indent forbidden
|
# Further indentation required as indentation is not distinguishable
|
||||||
foo = long_function_name(
|
def long_function_name(
|
||||||
var_one, var_two, var_three,
|
var_one, var_two, var_three,
|
||||||
var_four)
|
var_four):
|
||||||
|
print(var_one)
|
||||||
|
|
||||||
|
Optional:
|
||||||
|
# Extra indentation is not necessary.
|
||||||
|
foo = long_function_name(
|
||||||
|
var_one, var_two,
|
||||||
|
var_three, var_four)
|
||||||
|
|
||||||
Tabs or Spaces?
|
Tabs or Spaces?
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue