From e12e762a542fafca3857ada97626f166a1b71302 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Mon, 13 Jun 2011 12:48:33 -0400 Subject: [PATCH] PEP 8 updates on hanging continuation lines, based on discussion from python-ideas (contributed by Steven Klass). --- pep-0008.txt | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/pep-0008.txt b/pep-0008.txt index 3884f744c..f04e268d3 100644 --- a/pep-0008.txt +++ b/pep-0008.txt @@ -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?