在我注意到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
以接受以前的缩进样式?