Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3c69867

Browse files
partheadaniel-sanchegcf-owl-bot[bot]
authored
chore: move retry async check to wrap time (#668)
* chore: move retry async check to wrap time* 🦉 Updates from OwlBot post-processorSeehttps://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md* added no cover mark---------Co-authored-by: Daniel Sanche <d.sanche14@gmail.com>Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>Co-authored-by: Daniel Sanche <sanche@google.com>
1 parentb91ed19 commit3c69867

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

‎google/api_core/retry/retry_unary.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,7 @@ def retry_target(
141141

142142
forsleepinsleep_generator:
143143
try:
144-
result=target()
145-
ifinspect.isawaitable(result):
146-
warnings.warn(_ASYNC_RETRY_WARNING)
147-
returnresult
144+
returntarget()
148145

149146
# pylint: disable=broad-except
150147
# This function explicitly must deal with broad exceptions.
@@ -280,6 +277,8 @@ def __call__(
280277
Callable: A callable that will invoke ``func`` with retry
281278
behavior.
282279
"""
280+
ifinspect.iscoroutinefunction(func):
281+
warnings.warn(_ASYNC_RETRY_WARNING)
283282
ifself._on_errorisnotNone:
284283
on_error=self._on_error
285284

‎tests/unit/retry/test_retry_unary.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,20 @@ def test_retry_target_non_retryable_error(utcnow, sleep):
105105
)
106106
@pytest.mark.asyncio
107107
asyncdeftest_retry_target_warning_for_retry(utcnow,sleep):
108-
predicate=retry.if_exception_type(ValueError)
109-
target=mock.AsyncMock(spec=["__call__"])
108+
"""
109+
retry.Retry should raise warning when wrapping an async function.
110+
"""
111+
112+
asyncdeftarget():
113+
pass# pragma: NO COVER
114+
115+
retry_obj=retry.Retry()
110116

111117
withpytest.warns(Warning)asexc_info:
112-
#Note: predicate is just a filler and doesn't affect the test
113-
retry.retry_target(target,predicate,range(10),None)
118+
#raise warning when wrapping an async function
119+
retry_obj(target)
114120

115-
assertlen(exc_info)==2
121+
assertlen(exc_info)==1
116122
assertstr(exc_info[0].message)==retry.retry_unary._ASYNC_RETRY_WARNING
117123
sleep.assert_not_called()
118124

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp