Skip to content

Commit 935503f

Browse files
Bernd VerstCopilot
andcommitted
Use inspect.isawaitable in AsyncClientResiliencyInterceptor
Replace the ad-hoc `hasattr(result, '__await__')` check in `AsyncClientResiliencyInterceptor._record_outcome` with the canonical `inspect.isawaitable` predicate, and tighten the `on_recreate` callback annotation to `Callable[[], Union[None, Awaitable[object]]]` so it reflects the actual contract (sync callbacks return None, async callbacks return an Awaitable that we await). Addresses the github-code-quality 'Statement has no effect' warning surfaced on PR #135 by making the awaitable check explicit and type-driven. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 223ba40 commit 935503f

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

durabletask/internal/grpc_resiliency.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4+
import inspect
45
import random
56
import threading
67
from dataclasses import dataclass, field
7-
from typing import Callable, Optional
8+
from typing import Awaitable, Callable, Optional, Union
89

910
import grpc
1011
import grpc.aio
@@ -125,7 +126,7 @@ class AsyncClientResiliencyInterceptor(grpc.aio.UnaryUnaryClientInterceptor):
125126
def __init__(
126127
self,
127128
failure_tracker: FailureTracker,
128-
on_recreate: Callable[[], "Optional[object]"],
129+
on_recreate: Callable[[], Union[None, Awaitable[object]]],
129130
):
130131
self._failure_tracker = failure_tracker
131132
self._on_recreate = on_recreate
@@ -147,7 +148,7 @@ async def _record_outcome(self, method: str, error: Optional[BaseException]) ->
147148
if status_code is not None and is_client_transport_failure(method, status_code):
148149
if self._failure_tracker.record_failure():
149150
result = self._on_recreate()
150-
if hasattr(result, "__await__"):
151+
if inspect.isawaitable(result):
151152
await result
152153
else:
153154
self._failure_tracker.record_success()

0 commit comments

Comments
 (0)