mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-30 03:00:41 -04:00
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).
This commit is contained in:
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user