在我注意到之前,我只是flake8
用来快速检查我的 Python 3 代码pylint
。
在我的一个项目中,我有以下代码:
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
以接受以前的缩进样式呢?