出于可读性原因,我更喜欢对齐某些类型的语句,例如在以下情况中(这涉及一些 PyParsing 代码,但细节无关紧要):
_otherwise_stmt = _OTHERWISE ('otherwise statement')
_else_stmt = _ELSE ('else statement')
_end_stmt = _END ('end statement')
为此,pep8
提示 E221(“运算符前的多个空格”)和 E211(“'('”) 前的空格。如果我将 # noqa
放在在每一行的末尾,pep8
仍然 提示这些行。但是,对于我文件中其他地方的其他构造,# noqa
按预期工作。我对为什么 # noqa
没有使 pep8
对于这些特定结构按预期工作感到困惑。
这是 pep8
程序中的错误,还是我在这里做错了什么?
最佳答案
pep8
脚本只允许您使用 # noqa
注释禁用特定的错误代码。
参见 Error Codes table ;只有标有 (^)
的错误代码才能通过这种方式消除。 E211和E221不在其中(E2*代码都不在):
(^)
These checks can be disabled at the line level using the# noqa
special comment. This possibility should be reserved for special cases.
就个人而言,我更喜欢使用 flake8
tool ,它结合了 pep8
和 PyFlakes,让您可以更自由地使用 #noqa
标记。
关于python - 在某些情况下,pep8 是否无法识别 `# noqa`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28594049/