Skip to content

Commit fe5d119

Browse files
authored
Merge branch 'main' into renovate/all
2 parents e3b56c4 + c1b8afa commit fe5d119

File tree

8 files changed

+18
-10
lines changed

8 files changed

+18
-10
lines changed

google/api_core/bidi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ def close(self):
306306
self._request_queue.put(None)
307307
self.call.cancel()
308308
self._request_generator = None
309+
self._initial_request = None
310+
self._callbacks = []
309311
# Don't set self.call to None. Keep it around so that send/recv can
310312
# raise the error.
311313

@@ -717,6 +719,7 @@ def stop(self):
717719
_LOGGER.warning("Background thread did not exit.")
718720

719721
self._thread = None
722+
self._on_response = None
720723

721724
@property
722725
def is_active(self):

google/api_core/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,14 @@ def format_http_response_error(
517517
errors = payload.get("error", {}).get("errors", ())
518518
# In JSON, details are already formatted in developer-friendly way.
519519
details = payload.get("error", {}).get("details", ())
520-
error_info = list(
520+
error_info_list = list(
521521
filter(
522522
lambda detail: detail.get("@type", "")
523523
== "type.googleapis.com/google.rpc.ErrorInfo",
524524
details,
525525
)
526526
)
527-
error_info = error_info[0] if error_info else None
527+
error_info = error_info_list[0] if error_info_list else None
528528
message = _format_rest_error_message(error_message, method, url)
529529

530530
exception = from_http_status(

google/api_core/grpc_helpers_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ class _WrappedStreamStreamCall(
152152

153153

154154
# public type alias denoting the return type of async streaming gapic calls
155-
GrpcAsyncStream = _WrappedStreamResponseMixin[P]
155+
GrpcAsyncStream = _WrappedStreamResponseMixin
156156
# public type alias denoting the return type of unary gapic calls
157-
AwaitableGrpcCall = _WrappedUnaryResponseMixin[P]
157+
AwaitableGrpcCall = _WrappedUnaryResponseMixin
158158

159159

160160
def _wrap_unary_errors(callable_):

google/api_core/retry/retry_unary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def check_if_exists():
8383

8484

8585
def retry_target(
86-
target: Callable[_P, _R],
86+
target: Callable[[], _R],
8787
predicate: Callable[[Exception], bool],
8888
sleep_generator: Iterable[float],
8989
timeout: float | None = None,

google/api_core/retry/retry_unary_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async def check_if_exists():
9494

9595

9696
async def retry_target(
97-
target: Callable[_P, Awaitable[_R]],
97+
target: Callable[[], Awaitable[_R]],
9898
predicate: Callable[[Exception], bool],
9999
sleep_generator: Iterable[float],
100100
timeout: float | None = None,

noxfile.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,7 @@ def pytype(session):
275275
@nox.session(python=DEFAULT_PYTHON_VERSION)
276276
def mypy(session):
277277
"""Run type-checking."""
278-
# TODO(https://github.com/googleapis/python-api-core/issues/682):
279-
# Use the latest version of mypy instead of mypy<1.11.0
280-
session.install(".[grpc,async_rest]", "mypy<1.11.0")
278+
session.install(".[grpc,async_rest]", "mypy")
281279
session.install(
282280
"types-setuptools",
283281
"types-requests",

tests/asyncio/test_grpc_helpers_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def test_awaitable_grpc_call():
319319
"""
320320
AwaitableGrpcCall type should be an Awaitable and a grpc.aio.Call.
321321
"""
322-
instance = grpc_helpers_async.AwaitableGrpcCall[int]()
322+
instance = grpc_helpers_async.AwaitableGrpcCall()
323323
assert isinstance(instance, grpc.aio.Call)
324324
# should implement __await__
325325
assert hasattr(instance, "__await__")

tests/unit/test_bidi.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ def test_close(self):
296296
# ensure the request queue was signaled to stop.
297297
assert bidi_rpc.pending_requests == 1
298298
assert bidi_rpc._request_queue.get() is None
299+
# ensure request and callbacks are cleaned up
300+
assert bidi_rpc._initial_request is None
301+
assert not bidi_rpc._callbacks
299302

300303
def test_close_no_rpc(self):
301304
bidi_rpc = bidi.BidiRpc(None)
@@ -623,6 +626,8 @@ def cancel_side_effect():
623626
assert bidi_rpc.pending_requests == 1
624627
assert bidi_rpc._request_queue.get() is None
625628
assert bidi_rpc._finalized
629+
assert bidi_rpc._initial_request is None
630+
assert not bidi_rpc._callbacks
626631

627632
def test_reopen_failure_on_rpc_restart(self):
628633
error1 = ValueError("1")
@@ -777,6 +782,7 @@ def on_response(response):
777782
consumer.stop()
778783

779784
assert consumer.is_active is False
785+
assert consumer._on_response is None
780786

781787
def test_wake_on_error(self):
782788
should_continue = threading.Event()
@@ -884,6 +890,7 @@ def close_side_effect():
884890

885891
consumer.stop()
886892
assert consumer.is_active is False
893+
assert consumer._on_response is None
887894

888895
# calling stop twice should not result in an error.
889896
consumer.stop()

0 commit comments

Comments
 (0)