Black violates pep8 recommendation with long argument list
See original GitHub issueCurrently, black reformats long routine names as follow
# in:
def very_important_function(template: str, *variables, file: os.PathLike, engine: str, header: bool = True, debug: bool = False):
"""Applies `variables` to the `template` and writes to `file`."""
with open(file, 'w') as f:
...
# out:
def very_important_function(
template: str,
*variables,
file: os.PathLike,
engine: str,
header: bool = True,
debug: bool = False,
):
"""Applies `variables` to the `template` and writes to `file`."""
with open(file, "w") as f:
Desired style
The current style done by black violates pep8 recommendation
# Add 4 spaces (an extra level of indentation) to distinguish arguments from the rest.
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
The logic and motivation behind pep8 formatting, and against black, is that one wants to keep the indentation of the function definition continuation at a different level compared to the logic block. Otherwise, it’s harder to differentiate what’s one and what’s the other, despite the indented frowny face.
In fact, flake8 reports a pep8 violation for a case such as this
if path.suffix in (
'.js', '.json'
):
proto = Protocol.json
x.py:20:5: E125 continuation line with same indent as next logical line
Black current formatting would be equivalent to this
if path.suffix in (
'.js', '.json'
):
proto = Protocol.json
Which we can probably all agree is a bad idea.
Additional context from python-ideas mailing list
Issue Analytics
- State:
- Created 4 years ago
- Reactions:32
- Comments:54 (7 by maintainers)
Top Results From Across the Web
PEP-8: clarify if multiline argument list with a closing `)` on a ...
So the root of this argument is that Black produces code that isn't always in compliance with PEP 8. I say this is...
Read more >How to automatically break long string constants in Python ...
First make sure that you have a very recent Black formatter installed. Now just run black with the option --experimental-string-processing .
Read more >Brighten your code with Black code formatter.
Linters give information which part of the code violates PEP-8, but they do not give ... Black is the uncompromising Python code formatter....
Read more >Python programming is drowning in red tape - Hacker News
The dude writes "Black violates pep8 recommendation" in his title (notice recommendation), yet, feels strong enough to say "This is a bug.
Read more >Code Quality Assistance Tips and Tricks, or How to Make Your ...
So, as you can see, PyCharm supports PEP8 as the official Python style guide. If you explore the list of inspections ( Ctrl+Alt+S ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@JelleZijlstra Are you serious??? Reopen the issue right now or I am forking. This is a bug. Period. It does not comply with pep8. It does not comply with autopep8. It must be fixed.
Black isn’t going to change this style now because it would be too disruptive for our users.