From cd212d3cda5804e70ec8e6c1b89a4900bca8d75b Mon Sep 17 00:00:00 2001 From: Solomon Jacobs Date: Thu, 25 Jul 2024 07:58:47 +0200 Subject: [PATCH] Adjust configuration mypy The strict flag enables the following flags (the precise list depends on the mypy version, see mypy --help): --warn-unused-configs, --disallow-any-generics, --disallow-subclassing-any, --disallow-untyped-calls, --disallow-untyped-defs, --disallow-incomplete-defs, --check-untyped-defs, --disallow-untyped-decorators, --warn-redundant-casts, --warn-unused-ignores, --warn-return-any, --no-implicit-reexport, --strict-equality, --extra-checks This means mypy accepts the following code as valid: ``` import typing def ignore_without_code() -> int: return "a" # type: ignore def redundant_expr(x: int) -> int: return 1 if isinstance(x, int) else 2 def possible_undefined(x: int) -> int: if x > 0: result = 1 return result def any_explicit(_x: typing.Any) -> None: pass def any_expr() -> None: a = x # type: ignore[name-defined] ``` --- pyproject.toml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 1d4e9b9..1826d53 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,6 +25,14 @@ build-backend = "poetry.core.masonry.api" [tool.mypy] strict = true +enable_error_code = [ + "ignore-without-code", + "redundant-expr", + "possibly-undefined", +] +disallow_any_expr = true +disallow_any_explicit = true + [tool.isort] profile = "black"