diff --git a/pep-0008.txt b/pep-0008.txt index 381cb690b077..c0d29a482fd9 100644 --- a/pep-0008.txt +++ b/pep-0008.txt @@ -121,6 +121,51 @@ Optional:: var_one, var_two, var_three, var_four) +For dictionaries there is an extra rule. When placing a dictionary key on a new +line an additional hanging indent should be added. This is so it is easy to +differentiate between keys and values. + +Yes:: + + # Keys alligned with opening delimiter, values have an extra indent + mydict = {'firstkey': + 'a very very very very very long value', + 'secondkey': 'a short value', + 'thirdkey': 'a very very very' + ' long value that continues on the next line' + ' and even on the line after that.', + } + + # Keys one and values with two hanging indents + mydict = { + 'firstkey': + 'a very very very very very long value', + 'secondkey': 'a short value', + 'thirdkey': 'a very very very' + ' long value that continues on the next line' + ' and even on the line after that.', + } + + # Continuing value indented to column where the value starts + mydict = { + 'thirdkey': 'a very very very' + ' long value that continues on the next line' + ' and even on the line after that.', + } + + +No:: + + # Keys and values indented in the same way. + mydict = {'firstkey': + 'a very very very very very long value', + 'secondkey': 'a short value', + 'thirdkey': 'a very very very' + ' long value that continues on the next line', + ' and even on the line after that.' + } + + .. _`multiline if-statements`: When the conditional part of an ``if``-statement is long enough to require