mypy 和 pyproject.toml,选项仅在全球范围内有效

问题描述 投票:0回答:2

我希望仅对某些特定模块使用选项

disable_error_code = ["name-defined"]
ignore_missing_imports = true
,但我正在努力使其工作。 以下是我的非工作
pyproject.toml
文件的摘录:

[tool.mypy]
python_version = "3.9"
disallow_untyped_defs = true
show_error_codes = true
no_implicit_optional = true
warn_return_any = true
warn_unused_ignores = true
exclude = ["scripts", "docs", "test"]


[[tool.mypy.overrides]]
module = [
    "firstmodule",
    "secondmodule",
    "utils",
    "config",
]
disable_error_code = ["name-defined"]
ignore_missing_imports = true

更具体地说,如果我按照上面的指示保留

disable_error_code = ["name-defined"]
,那么我会得到以下类型的错误:

pyproject.toml:[module = “utils”]:每个模块部分应该只指定每个模块标志(disable_error_code)

如果我保留

ignore_missing_imports = true
如上所述,那么它会被忽略,并且会发出由于缺少导入而导致的错误。

如果相反,我将提到的两个选项移到

[tool.mypy]
下一切正常。

mypy pyproject.toml
2个回答
4
投票

我还想有选择地禁用还没有类型提示的包的警告,这种方法似乎对我有用:

[[tool.mypy.overrides]]
module = "firstmodule.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "secondmodule.*"
ignore_missing_imports = true

1
投票

到目前为止,只有全球支持的选项太多了。其中,

disable_error_code
。特别是,它会警告你

Per module sections should only specify per-module flags

© www.soinside.com 2019 - 2024. All rights reserved.