我有一些通过 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/