在某些情况下,pep8 是否无法识别 `#noqa`?

Does pep8 fail to recognize `# noqa` in some instances?

出于可读性原因,我更喜欢对齐某些类型的语句,例如在以下情况中(这涉及一些 PyParsing 代码,但细节无关紧要):

_otherwise_stmt = _OTHERWISE ('otherwise statement')
_else_stmt      = _ELSE      ('else statement')
_end_stmt       = _END       ('end statement')

为此,pep8抱怨E221("multiple spaces before operator")和E211("whitespace before '('")。如果我将 # noqa 放在每一行的末尾,pep8 still 会抱怨这些行。但是,对于我文件中其他地方的其他构造,# noqa 按预期工作。我对为什么 # noqa 不能使 pep8 对于这些特定结构按预期工作感到困惑。

这是 pep8 程序中的错误,还是我在这里做错了什么?

pep8 脚本仅允许您使用 # noqa 注释禁用特定错误代码。

Error Codes table;只有标有 (^) 的错误代码才能通过这种方式消除。 E211和E221不在其中(none of the E2* codes are):

(^) 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 标记。

这是一个 known issue(“# noqa 对于大多数错误”),取决于你问的是谁。

该工具确实允许您将 # noqa 用于某些警告,但不能用于 E221E211