vim-python-pep8-indent icon indicating copy to clipboard operation
vim-python-pep8-indent copied to clipboard

Indent dictionary values on a new line extra

Open JelteF opened this issue 9 years ago • 7 comments
trafficstars

This indents dictionaries in the following way:

mydict = {"12345":
              'abcde'}

JelteF avatar Oct 06 '16 20:10 JelteF

I like it. Do you have some reference, e.g. is it mentioned in PEP8?

Current behavior:

mydict = {"12345":
          'abcde'}

blueyed avatar Oct 06 '16 22:10 blueyed

I'm not sure about PEP 8, but pycodestyle will complain about this.

test.py:2:15: E127 continuation line over-indented for visual indent

myint avatar Oct 07 '16 04:10 myint

@blueyed, I like it as well, so much in fact that I assumed it would be allowed by PEP8. But as @myint notes it is indeed marked as wrong by pycodestyle. Looking at PEP8 itself it is not special cased and not even allowed. Because I think this indentation is much clearer I just sent the following to the python-ideas mailinglist:

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',
}

As opposed to this IMHO much less readable version:

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',
}

As you can see it is much harder in the second version to distinguish between keys and values.

JelteF avatar Oct 08 '16 19:10 JelteF

For reference: Guido likes it: https://mail.python.org/pipermail/python-ideas/2016-October/042754.html.

blueyed avatar Oct 08 '16 21:10 blueyed

I made a pull request in the peps repo: https://github.com/python/peps/pull/113 To make clear the current changes I made, do not actually create the example code shown there, only partly.

JelteF avatar Oct 09 '16 11:10 JelteF

Codecov Report

Merging #61 into master will increase coverage by 0.06%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #61      +/-   ##
==========================================
+ Coverage   92.75%   92.82%   +0.06%     
==========================================
  Files           1        1              
  Lines         207      209       +2     
==========================================
+ Hits          192      194       +2     
  Misses         15       15
Impacted Files Coverage Δ
indent/python.vim 92.82% <100%> (+0.06%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d9efc96...d19b456. Read the comment docs.

codecov[bot] avatar Jul 26 '18 09:07 codecov[bot]

I've rebased this.

We might add a configuration variable for it though, since it will trigger flake8/pycodestyle's E127, which might be annoying.

I've created https://github.com/PyCQA/pycodestyle/issues/785 to ask for relaxation of this in pycodestyle itself.

blueyed avatar Jul 26 '18 09:07 blueyed