如何让 mypy 全局忽略丢失的导入?

how to get mypy to globally ignore missing imports?

我有许多导入其他未类型化库的文件。

我已将此添加到 mypy.ini 例如:

[coloredlogs]
ignore_missing_imports = True

所以也许这对不检查库本身有效?例如,在 /venv 中但仍在 every.single.place 中导入了一个库,我收到了这些警告。

让忽略工作的唯一方法是在 every.single.import

上添加注释

import coloredlogs # type: ignore

参考资料:https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

您的配置语法错误。 example in the docs you've linked

[mypy-foobar.*]
ignore_missing_imports = True

所以你会想要

[mypy-coloredlogs.*]
ignore_missing_imports = True