Stricter mypy checks
You can enable optional checks to make mypy stricter than it is by default. Here is a small selection:1
enable_error_code = ["ignore-without-code"]
: no blanket# type: ignore
without error code – to avoid silencing unexpected errors and communicating why the type ignore is necessarywarn_unused_ignores
: no unnecessary type ignoresdisallow_untyped_defs
: no function definitions without proper annotationsdisallow_any_generics
: no generic types without explicit type arguments, for example,list[str]
instead oflist
warn_return_any
: noAny
return in a function that is annotated to return a non-Any
typewarn_unreachable
: no unreachable codewarn_redundant_casts
: no redundant type casts
I expect that some of these will become defaults in the future, at least I would like that.
With underscores, as expected by the
pyproject.toml
file under[tool.mypy]
.↩︎