Skip to content

Commit

Permalink
Reland "Move mypy config from agent-based pyproject.toml to root"
Browse files Browse the repository at this point in the history
This reverts commit 0c589fd24da1af2cf04fa774ee177d44e5f7b3e1.

Change-Id: Ife5e724dc7d437d54316518d01522d558398c878
  • Loading branch information
Synss committed Nov 15, 2024
1 parent 879f2bf commit 75c8f43
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 39 deletions.
4 changes: 4 additions & 0 deletions packages/cmk-agent-based/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion packages/cmk-agent-based/aspects.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 3 additions & 33 deletions packages/cmk-agent-based/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
32 changes: 32 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 75c8f43

Please sign in to comment.