How to ignore missing library stubs for mypy by adding to pyproject.toml

bax*_*axx 8 python mypy

I have some libraries which are returning the following error having run mypy .

module is installed, but missing library stubs or py.typed marker
Run Code Online (Sandbox Code Playgroud)

为了忽略这一点(因为我想忽略这个特定库的错误),我尝试将以下内容添加到 pyproject.toml 中:

+[mypy-<library name>.*]
+ignore_missing_imports = true
Run Code Online (Sandbox Code Playgroud)

然而,这会返回以下错误:

Invalid TOML file /home/...: Empty table name at line ...
Run Code Online (Sandbox Code Playgroud)

我的印象是这是正确的方法 - 但也许事情已经改变了。

我的问题是 - 我如何告诉 mypy 忽略缺少存根的特定库,并在pyproject.toml

编辑

我刚刚发现:toml 中的 mypy 覆盖被忽略?

这表明类似于:

[[tool.mypy.overrides]]
module = "library.*"
ignore_missing_imports = true
Run Code Online (Sandbox Code Playgroud)

这不是我记得的语法,所以需要仔细检查。

L D*_*L D 4

对于寻找此问题答案的其他人,除了该语法之外,您还可以执行以下操作:

[tool.mypy-<library name>]
ignore_missing_imports = true
Run Code Online (Sandbox Code Playgroud)

  • 请注意,这是“mypy.ini”文件的语法,而不是“pyproject.toml”的语法,请参阅[mypy配置文件](https://mypy.readthedocs.io/en/stable/config_file.html#the-mypy-配置文件) (4认同)