[Python-ideas] PEP8 dictionary indenting addition

Erik python at lucidity.plus.com
Mon Oct 10 21:00:40 EDT 2016


On 09/10/16 12:43, Paul Moore wrote:
> I'd probably lay this out as
>
> # Less indent needed for keys, so thirdkey fits better in this case
> 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',
> }

+1 from me on this general style of layout.

Why associate the indentation level with the name of the identifier 
being bound? Treat the opening parenthesis as beginning a "suite" of 
indented key/value pairs in the same way as a colon introduces an 
indented suite of statements in other constructs.

It may not be part of the formal syntax, but it's consistent with other 
constructs in the language that _are_ defined by the formal syntax.

E.


More information about the Python-ideas mailing list