vim-python-pep8-indent
vim-python-pep8-indent copied to clipboard
Indent dictionary values on a new line extra
This indents dictionaries in the following way:
mydict = {"12345":
'abcde'}
I like it. Do you have some reference, e.g. is it mentioned in PEP8?
Current behavior:
mydict = {"12345":
'abcde'}
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
@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.
For reference: Guido likes it: https://mail.python.org/pipermail/python-ideas/2016-October/042754.html.
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.
Codecov Report
Merging #61 into master will increase coverage by
0.06%. The diff coverage is100%.
@@ 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 dataPowered by Codecov. Last update d9efc96...d19b456. Read the comment docs.
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.