[Python-ideas] PEP8 dictionary indenting addition

Erik Bray erik.m.bray at gmail.com
Tue Oct 11 11:40:03 EDT 2016


On Sun, Oct 9, 2016 at 2:25 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Sat, Oct 08, 2016 at 09:26:13PM +0200, Jelte Fennema wrote:
>> I have an idea to improve indenting guidelines for dictionaries for better
>> readability: If a value in a dictionary literal is placed on a new line, it
>> should have (or at least be allowed to have) a n additional hanging indent.
>>
>> Below is an example:
>>
>> mydict = {'mykey':
>>               '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',
>> }
>
> Looks good to me, except that my personal preference for the implicit
> string concatenation (thirdkey) is to move the space to the
> following line, and (if possible) align the parts:
> mydict = {'mykey':
>               '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',
>           }

Heh--not to bikeshed, but my personal preference is to leave the
trailing space on the first line.  This is because by the time I've
started a new line (and possibly have spent time fussing with
indentation for the odd cases that my editor doesn't get quite right)
I'll have forgotten that I need to start the line with a space :)

Best,
Erik


More information about the Python-ideas mailing list