From 75c8f4375a52ea19c8a1c7d335c16682eb924e72 Mon Sep 17 00:00:00 2001 From: Mathias Laurin Date: Thu, 14 Nov 2024 16:25:10 +0100 Subject: [PATCH] Reland "Move mypy config from agent-based pyproject.toml to root" This reverts commit 0c589fd24da1af2cf04fa774ee177d44e5f7b3e1. Change-Id: Ife5e724dc7d437d54316518d01522d558398c878 --- packages/cmk-agent-based/BUILD | 4 +++ packages/cmk-agent-based/aspects.bzl | 2 +- .../cmk/agent_based/prediction_backend.py | 6 ++-- packages/cmk-agent-based/pyproject.toml | 36 ++----------------- .../agent_based/v1/test_checking_classes.py | 4 +-- pyproject.toml | 32 +++++++++++++++++ 6 files changed, 45 insertions(+), 39 deletions(-) diff --git a/packages/cmk-agent-based/BUILD b/packages/cmk-agent-based/BUILD index b04ed3dd8b8..ad5401cb3b6 100644 --- a/packages/cmk-agent-based/BUILD +++ b/packages/cmk-agent-based/BUILD @@ -9,6 +9,10 @@ load("@rules_mypy//mypy:mypy.bzl", "mypy_cli") mypy_cli( name = "mypy_cli", mypy_requirement = requirement("mypy"), + deps = [ + # for `plugins = ["pydantic.mypy"]` + requirement("pydantic"), + ], ) exports_files([ diff --git a/packages/cmk-agent-based/aspects.bzl b/packages/cmk-agent-based/aspects.bzl index 1954f042ee1..02cfcecc6a6 100644 --- a/packages/cmk-agent-based/aspects.bzl +++ b/packages/cmk-agent-based/aspects.bzl @@ -2,6 +2,6 @@ load("@rules_mypy//mypy:mypy.bzl", "mypy") mypy_aspect = mypy( mypy_cli = "@@//packages/cmk-agent-based:mypy_cli", - mypy_ini = "@@//packages/cmk-agent-based:pyproject.toml", + mypy_ini = "@@//:pyproject.toml", suppression_tags = ["no-mypy"], ) diff --git a/packages/cmk-agent-based/cmk/agent_based/prediction_backend.py b/packages/cmk-agent-based/cmk/agent_based/prediction_backend.py index 4277ac79324..254ebb7feda 100644 --- a/packages/cmk-agent-based/cmk/agent_based/prediction_backend.py +++ b/packages/cmk-agent-based/cmk/agent_based/prediction_backend.py @@ -18,19 +18,19 @@ _ONE_DAY = 24 * 3600 -class PredictionParameters(BaseModel, frozen=True): # type: ignore[misc] # hidden Any +class PredictionParameters(BaseModel, frozen=True): period: Literal["wday", "day", "hour", "minute"] horizon: int levels: tuple[Literal["absolute", "relative", "stdev"], tuple[float, float]] bound: tuple[float, float] | None = None -class InjectedParameters(BaseModel, frozen=True): # type: ignore[misc] # hidden Any +class InjectedParameters(BaseModel, frozen=True): meta_file_path_template: str predictions: Mapping[int, tuple[_Prediction | None, _EstimatedLevels | None]] -class PredictionInfo(BaseModel, frozen=True): # type: ignore[misc] # hidden Any +class PredictionInfo(BaseModel, frozen=True): valid_interval: tuple[int, int] metric: str direction: _Direction diff --git a/packages/cmk-agent-based/pyproject.toml b/packages/cmk-agent-based/pyproject.toml index 83ea92641d5..a65eb3c183e 100644 --- a/packages/cmk-agent-based/pyproject.toml +++ b/packages/cmk-agent-based/pyproject.toml @@ -36,39 +36,9 @@ ignore = [ #[tool.ruff.lint.isort] # see ruff.toml for the isort section -[tool.mypy] -follow_imports = "silent" -follow_imports_for_stubs = true -enable_error_code = [ - "explicit-override", - "ignore-without-code", - "mutable-override", - "possibly-undefined", - # Neeeds to be investigated - #"redundant-expr", - "redundant-self", - "truthy-bool", - "truthy-iterable", - "unimported-reveal", - "unused-awaitable", - "unused-ignore", -] -explicit_package_bases = true -packages = ["cmk", "tests"] -strict = true -# Miscellaneous stuff not in --strict -disallow_any_decorated = true -disallow_any_explicit = true -disallow_any_expr = true -disallow_any_generics = true -disallow_any_unimported = true -disallow_subclassing_any = true -no_implicit_optional = true -strict_optional = true -warn_unreachable = true -# hidden flags for PEP 688 compat, see https://github.com/python/mypy/issues/15313 -disable_bytearray_promotion = true -disable_memoryview_promotion = true +# [tool.mypy] +# Configure under the corresponding [[tool.mypy.overrides]] array +# in the root `pyproject.toml`. [tool.pytest.ini_options] consider_namespace_packages = true diff --git a/packages/cmk-agent-based/tests/cmk/agent_based/v1/test_checking_classes.py b/packages/cmk-agent-based/tests/cmk/agent_based/v1/test_checking_classes.py index 03e6e0f68dd..7292952a1f7 100644 --- a/packages/cmk-agent-based/tests/cmk/agent_based/v1/test_checking_classes.py +++ b/packages/cmk-agent-based/tests/cmk/agent_based/v1/test_checking_classes.py @@ -15,7 +15,7 @@ def test_evalable_float() -> None: inf = _EvalableFloat("inf") - assert literal_eval(f"{inf!r}") == float("inf") # type: ignore[misc] + assert literal_eval(f"{inf!r}") == float("inf") def test_service_label() -> None: @@ -93,7 +93,7 @@ def test_state() -> None: assert State["UNKNOWN"] is State.UNKNOWN with pytest.raises(TypeError): - _ = State.OK < State.WARN # type: ignore[operator,misc] + _ = State.OK < State.WARN # type: ignore[operator] @pytest.mark.parametrize( diff --git a/pyproject.toml b/pyproject.toml index 2139bacfa49..57a2b0a809e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -127,6 +127,10 @@ plugins = ["pydantic.mypy"] python_version = "3.12" scripts_are_modules = true +# do not descend into 3rd party dependencies +follow_imports = "silent" +follow_imports_for_stubs = true + # hidden flags for PEP 688 compat, see https://github.com/python/mypy/issues/15313 disable_bytearray_promotion = true disable_memoryview_promotion = true @@ -302,6 +306,34 @@ disallow_untyped_calls = true disallow_untyped_defs = true warn_unreachable = true +[[tool.mypy.overrides]] +module = "cmk.agent_based.*" +strict = true +enable_error_code = [ + "explicit-override", + "ignore-without-code", + "mutable-override", + "possibly-undefined", + # Needs to be investigated + # "redundant-expr", + "redundant-self", + "truthy-bool", + "truthy-iterable", + "unimported-reveal", + "unused-awaitable", + "unused-ignore", +] +# Miscellaneous stuff not in --strict +disallow_any_decorated = true +disallow_any_explicit = true +disallow_any_expr = true +disallow_any_generics = true +disallow_any_unimported = true +disallow_subclassing_any = true +no_implicit_optional = true +strict_optional = true +warn_unreachable = true + [tool.pydantic-mypy] init_forbid_extra = true init_typed = true