Pylint error code: C0330 (bad-continuation; i.e. "Wrong hanging indentation before block")
Original code snippet
class CheckHandler(object):
def __init__(self, file, out_json, check_dir=u".", files=None): # type: (str, bool, str, typing.List[str]) -> None
# Do this here so setup.py doesn't error
from snekchek.baseconfig import config
import configobj
Examples in the current _Black_ style
class CheckHandler(object):
def __init__(
self, file, out_json, check_dir=u".", files=None
): # type: (str, bool, str, typing.List[str]) -> None
# Do this here so setup.py doesn't error
from snekchek.baseconfig import config
import configobj
Note how the function parameters are on the same indentation level as the function body.
Desired style
# Ideal: comment moved down to fit width
# Note that getting this to work while preserving pylint/flake8 markers is quite the challenge
class CheckHandler(object):
def __init__(self, file, out_json, check_dir=u".", files=None):
# type: (str, bool, str, typing.List[str]) -> None
# Do this here so setup.py doesn't error
from snekchek.baseconfig import config
import configobj
# Alternatively, indent as recommended by pylint
class CheckHandler(object):
def __init__(
self, file, out_json, check_dir=u".", files=None
): # type: (str, bool, str, typing.List[str]) -> None
# Do this here so setup.py doesn't error
from snekchek.baseconfig import config
import configobj
It does this in various situations, but the core of the issue stays the same; The newer line ends up on the same indentation level as the function body
Black is unlikely to change such a core aspect of its formatting style at this stage. I recommend that you turn off any formatting-related errors from linters if you run Black on your codebase.
Is it possible to add a flag in the config to disable/change this behavior?
Sorry, no. As explained in the README, Black is striving for a single codestyle with minimal configuration.
If I understand correctly, Black has chosen to diverge from PEP8 on this point, because the latter emphasizes "... an extra level of indentation ..." for function arguments.
While I naively prefer Black's choice to that in PEP8, I ask confirmation from those who've studied this more: do Black and PEP8 make different choices for indentation of function arguments?
This breaks the Black's contract:
The coding style used by Black can be viewed as a strict subset of PEP 8.
README.md
I want to be sure I understand.
For our convenience, I identify
def f1_(
arg1, ...
# four-space indent
as Style A and
def f1_(
arg1, ...
# eight-space indent
as style B.
When vianney-g writes, "This breaks the Black's contract", I _think_ vianney-g is saying that:
I welcome any correction in my understanding.
Most helpful comment
I want to be sure I understand.
For our convenience, I identify
as Style A and
as style B.
When vianney-g writes, "This breaks the Black's contract", I _think_ vianney-g is saying that:
I welcome any correction in my understanding.