From 6890a1673a6fb123230fad4d869047dabdc55562 Mon Sep 17 00:00:00 2001 From: Jelte Fennema Date: Sun, 9 Oct 2016 12:39:50 +0200 Subject: [PATCH] PEP8: Dictionary values should have an extra indent --- pep-0008.txt | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pep-0008.txt b/pep-0008.txt index 381cb690b07..27a5090f0ad 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 aligned 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 with one and values with two levels of 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