From 4112847ff81ec8811c157e3439a27c98fdb1e816 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Mon, 16 Dec 2024 11:46:26 -0800 Subject: [PATCH 1/6] use latest mypy for check --- noxfile.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/noxfile.py b/noxfile.py index ada6f330..8b2b3859 100644 --- a/noxfile.py +++ b/noxfile.py @@ -275,9 +275,7 @@ def pytype(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def mypy(session): """Run type-checking.""" - # TODO(https://github.com/googleapis/python-api-core/issues/682): - # Use the latest version of mypy instead of mypy<1.11.0 - session.install(".[grpc,async_rest]", "mypy<1.11.0") + session.install(".[grpc]", "mypy") session.install( "types-setuptools", "types-requests", From eef37939d8fb3ede1d5bff629db21d1b0e5f48a7 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Mon, 16 Dec 2024 11:46:43 -0800 Subject: [PATCH 2/6] use separate variable for error_info list vs dict --- google/api_core/exceptions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google/api_core/exceptions.py b/google/api_core/exceptions.py index 5b25d124..e3eb696c 100644 --- a/google/api_core/exceptions.py +++ b/google/api_core/exceptions.py @@ -517,14 +517,14 @@ def format_http_response_error( errors = payload.get("error", {}).get("errors", ()) # In JSON, details are already formatted in developer-friendly way. details = payload.get("error", {}).get("details", ()) - error_info = list( + error_info_list = list( filter( lambda detail: detail.get("@type", "") == "type.googleapis.com/google.rpc.ErrorInfo", details, ) ) - error_info = error_info[0] if error_info else None + error_info = error_info_list[0] if error_info_list else None message = _format_rest_error_message(error_message, method, url) exception = from_http_status( From 175f46393deb69a3d08fdf2980bc1bc0106de3ce Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Mon, 16 Dec 2024 11:47:00 -0800 Subject: [PATCH 3/6] make wrapped call generic --- google/api_core/grpc_helpers_async.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/api_core/grpc_helpers_async.py b/google/api_core/grpc_helpers_async.py index 6feb2229..4bdc7182 100644 --- a/google/api_core/grpc_helpers_async.py +++ b/google/api_core/grpc_helpers_async.py @@ -36,7 +36,7 @@ # extra Python function spreads to every single send and receive. -class _WrappedCall(aio.Call): +class _WrappedCall(Generic[P], aio.Call): def __init__(self): self._call = None From 15e02b18089133117eabcbe52ed62ab22e580bfb Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Mon, 16 Dec 2024 11:47:13 -0800 Subject: [PATCH 4/6] fix typing for nullable retry functions --- google/api_core/retry/retry_unary.py | 2 +- google/api_core/retry/retry_unary_async.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/google/api_core/retry/retry_unary.py b/google/api_core/retry/retry_unary.py index ab1b4030..d5dff663 100644 --- a/google/api_core/retry/retry_unary.py +++ b/google/api_core/retry/retry_unary.py @@ -83,7 +83,7 @@ def check_if_exists(): def retry_target( - target: Callable[_P, _R], + target: Callable[[], _R], predicate: Callable[[Exception], bool], sleep_generator: Iterable[float], timeout: float | None = None, diff --git a/google/api_core/retry/retry_unary_async.py b/google/api_core/retry/retry_unary_async.py index 3bdf6c71..e76a37bb 100644 --- a/google/api_core/retry/retry_unary_async.py +++ b/google/api_core/retry/retry_unary_async.py @@ -94,7 +94,7 @@ async def check_if_exists(): async def retry_target( - target: Callable[_P, Awaitable[_R]], + target: Callable[[], Awaitable[_R]], predicate: Callable[[Exception], bool], sleep_generator: Iterable[float], timeout: float | None = None, From 62bdbe26b4890217f73261be5070d8e22a5a4aff Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Mon, 16 Dec 2024 11:53:41 -0800 Subject: [PATCH 5/6] include async_rest in mypy installation --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 8b2b3859..cffef972 100644 --- a/noxfile.py +++ b/noxfile.py @@ -275,7 +275,7 @@ def pytype(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def mypy(session): """Run type-checking.""" - session.install(".[grpc]", "mypy") + session.install(".[grpc,async_rest]", "mypy") session.install( "types-setuptools", "types-requests", From dc66845616a452b4d51430598e6168a4fd3a8b9f Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 17 Dec 2024 09:58:16 -0800 Subject: [PATCH 6/6] removed generic application --- google/api_core/grpc_helpers_async.py | 6 +++--- tests/asyncio/test_grpc_helpers_async.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/google/api_core/grpc_helpers_async.py b/google/api_core/grpc_helpers_async.py index 4bdc7182..26960456 100644 --- a/google/api_core/grpc_helpers_async.py +++ b/google/api_core/grpc_helpers_async.py @@ -36,7 +36,7 @@ # extra Python function spreads to every single send and receive. -class _WrappedCall(Generic[P], aio.Call): +class _WrappedCall(aio.Call): def __init__(self): self._call = None @@ -152,9 +152,9 @@ class _WrappedStreamStreamCall( # public type alias denoting the return type of async streaming gapic calls -GrpcAsyncStream = _WrappedStreamResponseMixin[P] +GrpcAsyncStream = _WrappedStreamResponseMixin # public type alias denoting the return type of unary gapic calls -AwaitableGrpcCall = _WrappedUnaryResponseMixin[P] +AwaitableGrpcCall = _WrappedUnaryResponseMixin def _wrap_unary_errors(callable_): diff --git a/tests/asyncio/test_grpc_helpers_async.py b/tests/asyncio/test_grpc_helpers_async.py index d8f20ae4..aa8d5d10 100644 --- a/tests/asyncio/test_grpc_helpers_async.py +++ b/tests/asyncio/test_grpc_helpers_async.py @@ -319,7 +319,7 @@ def test_awaitable_grpc_call(): """ AwaitableGrpcCall type should be an Awaitable and a grpc.aio.Call. """ - instance = grpc_helpers_async.AwaitableGrpcCall[int]() + instance = grpc_helpers_async.AwaitableGrpcCall() assert isinstance(instance, grpc.aio.Call) # should implement __await__ assert hasattr(instance, "__await__")