Search code examples
pythonpep8python-black

How to stop Black from removing new lines in function call args?


I want to document an external function:

strange_function(
    # Comments about what this argument does
    param_1=True,

    # Comments about what this argument does
    param_2=False,
)

Black reformats it as:

strange_function(
    # Comments about what this argument does
    param_1=True,
    # Comments about what this argument does
    param_2=False,
)

I want the new line between param_1 and param_2 because comments are more readable that way. But black removes this. How do it stop it from doing so?


Solution

  • You cannot.

    Black is very unforgiving, giving you only a single knob to turn: how many characters per line to allow.