question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Black violates pep8 recommendation with long argument list

See original GitHub issue

Currently, 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:closed
  • Created 4 years ago
  • Reactions:32
  • Comments:54 (7 by maintainers)

github_iconTop GitHub Comments

45reactions
stefanoborinicommented, Dec 13, 2019

@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.

27reactions
JelleZijlstracommented, Dec 13, 2019

Black isn’t going to change this style now because it would be too disruptive for our users.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found