Skip to content

Commit 31853bb

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

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

pep-0008.txt

+43
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,49 @@ 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+
# Keys alligned with opening delimiter, values have an extra indent
130+
mydict = {'firstkey':
131+
'a very very very very very long value',
132+
'secondkey': 'a short value',
133+
'thirdkey': 'a very very very'
134+
' long value that continues on the next line'
135+
' and even on the line after that.',
136+
}
137+
138+
# Keys one and values with two hanging indents
139+
mydict = {
140+
'firstkey':
141+
'a very very very very very long value',
142+
'secondkey': 'a short value',
143+
'thirdkey': 'a very very very'
144+
' long value that continues on the next line'
145+
' and even on the line after that.',
146+
}
147+
148+
# Continuing value indented to column where the value starts
149+
mydict = {
150+
'thirdkey': 'a very very very'
151+
' long value that continues on the next line'
152+
' and even on the line after that.',
153+
}
154+
155+
156+
No::
157+
# Keys and values indented in the same way.
158+
mydict = {'firstkey':
159+
'a very very very very very long value',
160+
'secondkey': 'a short value',
161+
'thirdkey': 'a very very very'
162+
' long value that continues on the next line',
163+
' and even on the line after that.'
164+
}
165+
166+
124167
.. _`multiline if-statements`:
125168

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

0 commit comments

Comments
 (0)