From 1d898ece5fa2c7170cea9ba6eda34df876b2e701 Mon Sep 17 00:00:00 2001 From: lczyk Date: Wed, 3 Jun 2026 10:13:17 +0100 Subject: [PATCH] fix: resolve ty type errors in check tag discrimination narrow check to Mapping before key lookup and build the tag list by membership instead of set intersection so the return type stays str; cast the marshalled checks dict in the new test. --- rockcraft/pebble.py | 6 ++++-- tests/unit/test_project.py | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/rockcraft/pebble.py b/rockcraft/pebble.py index f62e33ca3..87ff9cc67 100644 --- a/rockcraft/pebble.py +++ b/rockcraft/pebble.py @@ -194,16 +194,18 @@ def _get_check_tag(check: Mapping[str, Any] | _BaseCheck) -> str: return "tcp" if isinstance(check, ExecCheck): return "exec" + if not isinstance(check, Mapping): + raise CraftValidationError(f"Unknown check type for {check!r}.") tags = ("http", "tcp", "exec") - check_types = check.keys() & tags + check_types = [tag for tag in tags if tag in check] match len(check_types): case 0: raise CraftValidationError( f"Must specify exactly one of {', '.join(tags)} for each check." ) case 1: - return check_types.pop() + return check_types[0] case _: raise CraftValidationError( f"Multiple check types specified ({', '.join(sorted(check_types))}). " diff --git a/tests/unit/test_project.py b/tests/unit/test_project.py index 101a3a82f..fe6c4f151 100644 --- a/tests/unit/test_project.py +++ b/tests/unit/test_project.py @@ -19,7 +19,7 @@ import subprocess import warnings from pathlib import Path -from typing import cast +from typing import Any, cast import pydantic import pytest @@ -884,7 +884,8 @@ def test_project_marshal_exec_check_emits_no_pydantic_warning(): warnings.simplefilter("always") dumped = project.marshal() - assert dumped["checks"]["online"]["exec"]["command"] == "/bin/healthcheck" + checks = cast(dict[str, Any], dumped["checks"]) + assert checks["online"]["exec"]["command"] == "/bin/healthcheck" assert not any( "PydanticSerializationUnexpectedValue" in str(w.message) for w in caught )