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

chore: move retry async check to wrap time#668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
parthea merged 7 commits intomainfrommove_async_warning
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletionsgoogle/api_core/retry/retry_unary.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,10 +141,7 @@ def retry_target(

for sleep in sleep_generator:
try:
result = target()
if inspect.isawaitable(result):
warnings.warn(_ASYNC_RETRY_WARNING)
return result
return target()

# pylint: disable=broad-except
# This function explicitly must deal with broad exceptions.
Expand DownExpand Up@@ -280,6 +277,8 @@ def __call__(
Callable: A callable that will invoke ``func`` with retry
behavior.
"""
if inspect.iscoroutinefunction(func):
warnings.warn(_ASYNC_RETRY_WARNING)
if self._on_error is not None:
on_error = self._on_error

Expand Down
16 changes: 11 additions & 5 deletionstests/unit/retry/test_retry_unary.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -105,14 +105,20 @@ def test_retry_target_non_retryable_error(utcnow, sleep):
)
@pytest.mark.asyncio
async def test_retry_target_warning_for_retry(utcnow, sleep):
predicate = retry.if_exception_type(ValueError)
target = mock.AsyncMock(spec=["__call__"])
"""
retry.Retry should raise warning when wrapping an async function.
"""

async def target():
pass # pragma: NO COVER

retry_obj = retry.Retry()

with pytest.warns(Warning) as exc_info:
#Note: predicate is just a filler and doesn't affect the test
retry.retry_target(target, predicate, range(10), None)
#raise warning when wrapping an async function
retry_obj(target)

assert len(exc_info) ==2
assert len(exc_info) ==1
assert str(exc_info[0].message) == retry.retry_unary._ASYNC_RETRY_WARNING
sleep.assert_not_called()

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp