我为 Salt 编写了一个模块。通过 documentation它将 __salt__ 对象添加到 builtins 中。所以,当我运行 prospector 和 mypy 时,pyflake 警告我 __salt__ 是未定义的, >__salt__ 未定义!我可以忽略带有 # noqa: F821 的 pyflake 或带有 # type: ignore 的 mypy .
问题来了!如何忽略它们?
请您参考如下方法:
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 是忽略两者的正确方法。
