python - 如何避免 pylint 和 pycodestyle 之间关于缩进样式的冲突

标签 python pylint pep8

我有一些通过 pylint 运行的 python 代码,我决定也通过 pycodestyle 运行。

为了避免在 with 语句中出现长行,我执行以下操作:

with my_context_manager(
    argument1,
    argument2) as something:
    rest_of_my_code

但是 pycodestyle 告诉我

E125 continuation line with same indent as next logical line

所以我进一步缩进,如下所示:

with my_context_manager(
        argument1,
        argument2) as something:
    rest_of_my_code

但是现在 pylint 告诉我:

Wrong hanging indentation (remove 4 spaces).

是否有更好的解决方案来满足两个代码质量检查员的要求?


注一

如果行不是太长(不幸的是,情况并非总是如此),以下两个样式检查器都不会提出任何投诉:

with my_context_manager(argument1,
                        argument2) as something:
    rest_of_my_code

注2

为了回答评论,我尝试了以下方法:

with my_context_manager(
    argument1,
    argument2) as something:
        rest_of_my_code

奇怪的是 pycodestyle 仍然说 E125 continuation line with same indent as next logical line 关于与以前相同的行(带有 argument2 的行) .

最佳答案

您可以禁用 pylint 中的检查(在 .pylintrc 中,将 bad-continuation 添加到 MESSAGE CONTROL 部分的 disable 选项中文件)。

~/.pylintrc

[MESSAGES CONTROL]
disable=bad-continuation,...

有关 message-control 的更多信息,请参阅常见问题解答配置

关于python - 如何避免 pylint 和 pycodestyle 之间关于缩进样式的冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41699495/

相关文章:

python - Pyplot - 如果数据小于零,则更改线的颜色?

python - 无法在Python中使用.format()打印time()

python - 用 Pandas 附加到数据框单元格?

python - 展开元组/列表时不需要的部分

Pylint - 使 pylintrc 配置文件极简

python - 我应该在 Python 中为所有非 API 成员添加下划线前缀吗?

Python 命名约定——namedtuples

python - 我如何在 python 中使用 cssutils 编辑规则

python - pylint 无法导入自定义模块和函数(模块中无名称)

python - 导入行 : E501 line too long 中的 PEP8 错误