Skip to content

Black does not create pylint-compatible code #1127

@Martmists-GH

Description

@Martmists-GH

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: styleWhat do we want Blackened code to look like?

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions