Skip to content

Commit 8a77804

Browse files
committed
PEP8: Dictionary values should have an extra indent
1 parent 3ff642e commit 8a77804

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

pep-0008.txt

+45
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,51 @@ Optional::
121121
var_one, var_two,
122122
var_three, var_four)
123123

124+
For dictionaries there is an extra rule. When placing a dictionary key on a new
125+
line an additional hanging indent should be added. This is so it is easy to
126+
differentiate between keys and values.
127+
128+
Yes::
129+
130+
# Keys alligned with opening delimiter, values have an extra indent
131+
mydict = {'firstkey':
132+
'a very very very very very long value',
133+
'secondkey': 'a short value',
134+
'thirdkey': 'a very very very'
135+
' long value that continues on the next line'
136+
' and even on the line after that.',
137+
}
138+
139+
# Keys one and values with two hanging indents
140+
mydict = {
141+
'firstkey':
142+
'a very very very very very long value',
143+
'secondkey': 'a short value',
144+
'thirdkey': 'a very very very'
145+
' long value that continues on the next line'
146+
' and even on the line after that.',
147+
}
148+
149+
# Continuing value indented to column where the value starts
150+
mydict = {
151+
'thirdkey': 'a very very very'
152+
' long value that continues on the next line'
153+
' and even on the line after that.',
154+
}
155+
156+
157+
No::
158+
159+
# Keys and values indented in the same way.
160+
mydict = {'firstkey':
161+
'a very very very very very long value',
162+
'secondkey': 'a short value',
163+
'thirdkey': 'a very very very'
164+
' long value that continues on the next line',
165+
' and even on the line after that.'
166+
}
167+
168+
124169
.. _`multiline if-statements`:
125170

126171
When the conditional part of an ``if``-statement is long enough to require

0 commit comments

Comments
 (0)