From 6f9f2c72db03162f703d36352c22ee86ea93e660 Mon Sep 17 00:00:00 2001 From: majdyz Date: Fri, 10 Apr 2026 23:59:36 +0000 Subject: [PATCH] test(util/service): use Protocol cast instead of type: ignore Address CodeRabbit feedback on the new GraphValidationError round-trip tests: the file already has a ``_SupportsGetReturn`` Protocol pattern and coding guidelines forbid ``# type: ignore`` suppressors. Add ``_SupportsHandleCallMethodResponse`` Protocol alongside the existing one, cast the test client to it, and drop the two ``# type: ignore[attr-defined]`` suppressions added for the new tests. Pre-existing suppressions on older tests are left untouched (separate concern, out of scope for this PR). --- .../backend/backend/util/service_test.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/autogpt_platform/backend/backend/util/service_test.py b/autogpt_platform/backend/backend/util/service_test.py index 8d5c8444f1..6aff250236 100644 --- a/autogpt_platform/backend/backend/util/service_test.py +++ b/autogpt_platform/backend/backend/util/service_test.py @@ -30,6 +30,12 @@ class _SupportsGetReturn(Protocol): def _get_return(self, expected_return: TypeAdapter | None, result: Any) -> Any: ... +class _SupportsHandleCallMethodResponse(Protocol): + def _handle_call_method_response( + self, *, response: Any, method_name: str + ) -> Any: ... + + class ServiceTest(AppService): def __init__(self): super().__init__() @@ -516,10 +522,13 @@ class TestHTTPErrorRetryBehavior: "400 Bad Request", request=Mock(), response=mock_response ) - client = get_service_client(ServiceTestClient) + client = cast( + _SupportsHandleCallMethodResponse, + get_service_client(ServiceTestClient), + ) with pytest.raises(GraphValidationError) as exc_info: - client._handle_call_method_response( # type: ignore[attr-defined] + client._handle_call_method_response( response=mock_response, method_name="test_method" ) @@ -540,10 +549,13 @@ class TestHTTPErrorRetryBehavior: "400 Bad Request", request=Mock(), response=mock_response ) - client = get_service_client(ServiceTestClient) + client = cast( + _SupportsHandleCallMethodResponse, + get_service_client(ServiceTestClient), + ) with pytest.raises(GraphValidationError) as exc_info: - client._handle_call_method_response( # type: ignore[attr-defined] + client._handle_call_method_response( response=mock_response, method_name="test_method" )