Skip to content

Commit

Permalink
PEP8: Dictionary values should have an extra indent
Browse files Browse the repository at this point in the history
  • Loading branch information
JelteF committed Oct 9, 2016
1 parent 3ff642e commit 31853bb
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pep-0008.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,49 @@ 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
Expand Down

0 comments on commit 31853bb

Please sign in to comment.