From 7a414712b123932b1e05ebfa2577e912385c617a Mon Sep 17 00:00:00 2001 From: Fanis Tharropoulos Date: Sun, 16 Feb 2025 12:19:11 +0200 Subject: [PATCH 1/3] chore: cast kwargs as any in api call module mypy doesn't infer the typed dict type correctly, resulting in type errors, this isn't ideal. --- src/typesense/api_call.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/typesense/api_call.py b/src/typesense/api_call.py index 47d0eec..bf0fc3d 100644 --- a/src/typesense/api_call.py +++ b/src/typesense/api_call.py @@ -334,7 +334,7 @@ def _execute_request( as_json: typing.Literal[True], last_exception: typing.Union[None, Exception] = None, num_retries: int = 0, - **kwargs: typing.Unpack[SessionFunctionKwargs[TParams, TBody]], + **kwargs: typing.Any, ) -> TEntityDict: """ Execute a request to the Typesense API with retry logic. @@ -373,7 +373,7 @@ def _execute_request( as_json: typing.Literal[False], last_exception: typing.Union[None, Exception] = None, num_retries: int = 0, - **kwargs: typing.Unpack[SessionFunctionKwargs[TParams, TBody]], + **kwargs: typing.Any, ) -> str: """ Execute a request to the Typesense API with retry logic. @@ -411,7 +411,7 @@ def _execute_request( as_json: typing.Union[typing.Literal[True], typing.Literal[False]] = True, last_exception: typing.Union[None, Exception] = None, num_retries: int = 0, - **kwargs: typing.Unpack[SessionFunctionKwargs[TParams, TBody]], + **kwargs: typing.Any, ) -> typing.Union[TEntityDict, str]: """ Execute a request to the Typesense API with retry logic. @@ -493,7 +493,7 @@ def _make_request_and_process_response( def _prepare_request_params( self, endpoint: str, - **kwargs: typing.Unpack[SessionFunctionKwargs[TParams, TBody]], + **kwargs: typing.Any, ) -> typing.Tuple[Node, str, SessionFunctionKwargs[TParams, TBody]]: node = self.node_manager.get_node() url = node.url() + endpoint From f354e6aa2ffa325e1825a53a9bc44d168cd5e59e Mon Sep 17 00:00:00 2001 From: Fanis Tharropoulos Date: Sun, 16 Feb 2025 12:30:23 +0200 Subject: [PATCH 2/3] test: change integration test for debug to avoid future failures - Check for existence of keys and assert their types, instead of checking for their values --- tests/debug_test.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/debug_test.py b/tests/debug_test.py index d491d17..4f13d5f 100644 --- a/tests/debug_test.py +++ b/tests/debug_test.py @@ -47,9 +47,11 @@ def test_retrieve(fake_debug: Debug) -> None: def test_actual_retrieve(actual_debug: Debug) -> None: - """Test that the Debug object can retrieve a debug on Typesense server.""" - json_response: DebugResponseSchema = {"state": 1, "version": "27.0"} - + """Test that the Debug object can retrieve a debug on Typesense server and verify response structure.""" response = actual_debug.retrieve() - assert response == json_response + assert "state" in response + assert "version" in response + + assert isinstance(response["state"], int) + assert isinstance(response["version"], str) From e1f88c29cce4db966606effe7d559b5d81a5d9a0 Mon Sep 17 00:00:00 2001 From: Fanis Tharropoulos Date: Wed, 19 Feb 2025 02:01:05 +0200 Subject: [PATCH 3/3] fix(api_call): use SessionFunctionKwargs directly instead of unpacking --- src/typesense/api_call.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/typesense/api_call.py b/src/typesense/api_call.py index bf0fc3d..90e1929 100644 --- a/src/typesense/api_call.py +++ b/src/typesense/api_call.py @@ -334,7 +334,7 @@ def _execute_request( as_json: typing.Literal[True], last_exception: typing.Union[None, Exception] = None, num_retries: int = 0, - **kwargs: typing.Any, + **kwargs: SessionFunctionKwargs[TParams, TBody], ) -> TEntityDict: """ Execute a request to the Typesense API with retry logic. @@ -373,7 +373,7 @@ def _execute_request( as_json: typing.Literal[False], last_exception: typing.Union[None, Exception] = None, num_retries: int = 0, - **kwargs: typing.Any, + **kwargs: SessionFunctionKwargs[TParams, TBody], ) -> str: """ Execute a request to the Typesense API with retry logic. @@ -411,7 +411,7 @@ def _execute_request( as_json: typing.Union[typing.Literal[True], typing.Literal[False]] = True, last_exception: typing.Union[None, Exception] = None, num_retries: int = 0, - **kwargs: typing.Any, + **kwargs: SessionFunctionKwargs[TParams, TBody], ) -> typing.Union[TEntityDict, str]: """ Execute a request to the Typesense API with retry logic. @@ -473,7 +473,7 @@ def _make_request_and_process_response( url: str, entity_type: typing.Type[TEntityDict], as_json: bool, - **kwargs: typing.Any, + **kwargs: SessionFunctionKwargs[TParams, TBody], ) -> typing.Union[TEntityDict, str]: """Make the API request and process the response.""" request_response = self.request_handler.make_request( @@ -493,7 +493,7 @@ def _make_request_and_process_response( def _prepare_request_params( self, endpoint: str, - **kwargs: typing.Any, + **kwargs: SessionFunctionKwargs[TParams, TBody], ) -> typing.Tuple[Node, str, SessionFunctionKwargs[TParams, TBody]]: node = self.node_manager.get_node() url = node.url() + endpoint