Skip to content

Commit 1ccadb1

Browse files
committed
fixed issue with py310
1 parent 0500b8b commit 1ccadb1

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

google/api_core/retry_streaming_async.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ async def retry_target_generator(
5252
timeout: Optional[float] = None,
5353
on_error: Optional[Callable[[Exception], None]] = None,
5454
exception_factory: Optional[
55-
Callable[
56-
[List[Exception], bool, float], Tuple[Exception, Optional[Exception]]
57-
]
55+
Callable[[List[Exception], bool, float], Tuple[Exception, Optional[Exception]]]
5856
] = None,
5957
**kwargs,
6058
) -> AsyncGenerator[T, None]:
@@ -126,7 +124,7 @@ def on_error(e):
126124
filter_retry_wrapped = retryable_with_filter(target)
127125
```
128126
"""
129-
subgenerator : Optional[AsyncIterator[T]] = None
127+
subgenerator: Optional[AsyncIterator[T]] = None
130128
timeout = kwargs.get("deadline", timeout)
131129
deadline: Optional[float] = time.monotonic() + timeout if timeout else None
132130
# keep track of retryable exceptions we encounter to pass in to exception_factory
@@ -140,9 +138,11 @@ def on_error(e):
140138
# Start a new retry loop
141139
try:
142140
# generator may be raw iterator, or wrapped in an awaitable
143-
gen_instance: Union[AsyncIterable[T], Awaitable[AsyncIterable[T]]] = target()
141+
gen_instance: Union[
142+
AsyncIterable[T], Awaitable[AsyncIterable[T]]
143+
] = target()
144144
try:
145-
gen_instance = await gen_instance # type: ignore
145+
gen_instance = await gen_instance # type: ignore
146146
except TypeError:
147147
# was not awaitable
148148
pass
@@ -156,7 +156,7 @@ def on_error(e):
156156
while True:
157157
## Read from Subgenerator
158158
if supports_send:
159-
next_value = await subgenerator.asend(sent_in) # type: ignore
159+
next_value = await subgenerator.asend(sent_in) # type: ignore
160160
else:
161161
next_value = await subgenerator.__anext__()
162162
## Yield from Wrapper to caller
@@ -175,7 +175,9 @@ def on_error(e):
175175
# bare except catches any exception passed to `athrow`
176176
# delegate error handling to subgenerator
177177
if getattr(subgenerator, "athrow", None):
178-
await cast(AsyncGenerator[T, None], subgenerator).athrow(*sys.exc_info())
178+
await cast(AsyncGenerator[T, None], subgenerator).athrow(
179+
*sys.exc_info()
180+
)
179181
else:
180182
raise
181183
return

tests/asyncio/test_retry_async.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ async def test___call___generator_send_retry(self, sleep):
605605

606606
# error thrown on 3
607607
# generator should contain 0, 1, 2 looping
608+
generator = retry_(self._generator_mock)(error_on=3, ignore_sent=True)
608609
assert await generator.__anext__() == 0
609610
unpacked = [await generator.asend(i) for i in range(10)]
610611
assert unpacked == [1, 2, 0, 1, 2, 0, 1, 2, 0, 1]

tests/unit/test_retry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ def test___call___with_generator_send_retry(self, sleep):
643643
result.send("can not send to fresh generator")
644644
assert exc_info.match("can't send non-None value")
645645
# initiate iteration with None
646+
result = retry_(self._generator_mock)(error_on=3, ignore_sent=True)
646647
assert result.send(None) == 0
647648
# error thrown on 3
648649
# generator should contain 0, 1, 2 looping

0 commit comments

Comments
 (0)