Pylint vs. flake8悬挂缩进

时间:2017-08-25 12:06:38

标签: python python-3.x pylint flake8 coding-style

在我注意到flake8之前,我只使用pylint来快速检查我的Python 3代码。

在我的一个项目中,我有以下代码:

def strace(self):
    """Dumps a stack trace to a file."""
    try:
        with NamedTemporaryFile(
                'w', prefix=self._file_prefix, suffix='.stacktrace',
                dir=STRACE_DIR, delete=False) as tmp:
            tmp.write(format_exc())

根据flake8我正确缩进了这一点,因为缩进次数较少

def strace(self):
    """Dumps a stack trace to a file."""
    try:
        with NamedTemporaryFile(
            'w', prefix=self._file_prefix, suffix='.stacktrace',
            dir=STRACE_DIR, delete=False) as tmp:
            tmp.write(format_exc())

会导致错误:

homie/api/interface.py:300:5: E129 visually indented line with same indent as next logical line

然而pylint抱怨前者的风格,同时接受后者。

C:299, 0: Wrong hanging indentation (remove 4 spaces).
                    'w', prefix=self._file_prefix, suffix='.stacktrace',
                |   ^ (bad-continuation)
C:300, 0: Wrong hanging indentation (remove 4 spaces).
                    dir=STRACE_DIR, delete=False) as tmp:
                |   ^ (bad-continuation)

根据PEP8,前一种风格应该是正确的。 那么如何配置pylint以接受以前的缩进样式?

0 个答案:

没有答案