How can I make the prettifier autopep8
and the linter pylint
agree on how to indent my code, without disabling indentation formatting/linting altogether? I don't mind that much if it's the first or the second formatting, as long as I can hit Alt+F
in VSCode and trust the output.
The prettifier wants the code to be indented like this...
# autopep8 prettifier
def sum(
a: int,
b: int
) -> int:
"""Return the sum of a and b."""
return a + b
... but the linter wants it like this.
# pylint linter
def sum(
a: int,
b: int
) -> int:
"""Return the sum of a and b."""
return a + b
The PEP8 standard lists this as a way to format the function, but they don't mention how to indent when the closing parenthesis is put on a separate line. I really prefer have the extra line break because this puts the output format on its own line, it reduces the urge to have a blank line as the first line in the body of the function. I slightly prefer the first option above as this one aligns the closing parenthesis with the line that has to opening one. Google’s Python Style Guide recommends the first indentation example when using type hints.
# PEP8 standard
def sum(
a: int,
b: int) -> int:
"""Return the sum of a and b."""
return a + b
(For the above example, it would be better to simply put the function declaration on a single line, but this is not always possible without making the line too long.)