设置 pyflake 和 mypy 忽略同一行

Set pyflake AND mypy ignore same line

我为 Salt 编写了一个模块。通过 documentation 它将 __salt__ 对象添加到 builtins 中。因此,pyflake 警告我 运行 prospectormypy[= 时未定义 __salt__ 26=] 表示相同,即 __salt__ 未定义!我可以忽略带有 # noqa: F821pyflake 或带有 # type: ignoremypy

问题来了!如何忽略他们两个?

PEP 484 在 section on type comments 末尾指定以下内容:

In some cases, linting tools or other comments may be needed on the same line as a type comment. In these cases, the type comment should be before other comments and linting markers:

# type: ignore # ~comment or other marker~

因此,正如 Ryan Tam 所建议的,# type: ignore # noqa 是忽略两者的正确方法。