Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mypy and pyproject.toml, options only work globally

I wish to use the options disable_error_code = ["name-defined"] and ignore_missing_imports = true only for some specific modules, but I am struggling to make it work. The following is an excerpt of my non-working pyproject.toml file:

[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

More specifically, if I keep disable_error_code = ["name-defined"] as indicated above, then I get the following kind of errors:

pyproject.toml: [module = "utils"]: Per-module sections should only specify per-module flags (disable_error_code)

If I keep ignore_missing_imports = true as indicated above, then it is ignored and errors due to missing import are signaled.

If instead I move the mentioned two options under [tool.mypy] everything works.

like image 294
Barzi2001 Avatar asked Sep 03 '25 09:09

Barzi2001


2 Answers

I also wanted to selectively disable warnings for packages that don't yet have type hints, and this approach seems to work for me:

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

[[tool.mypy.overrides]]
module = "secondmodule.*"
ignore_missing_imports = true
like image 110
Jeff Garbers Avatar answered Sep 04 '25 23:09

Jeff Garbers


I found that I could use a single [[tool.mypy.overrides]] section with a comma-separated list of package names, when disabling missing import warnings - e.g.

[[tool.mypy.overrides]]
module = "firstmodule.*,secondmodule.*"
ignore_missing_imports = true
like image 24
Will Keeling Avatar answered Sep 04 '25 23:09

Will Keeling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!