Skip to content

Commit

Permalink
Use inspect.iscoroutinefunction instead of `asyncio.iscoroutinefunc…
Browse files Browse the repository at this point in the history
…tion`
  • Loading branch information
edgarrmondragon committed Oct 17, 2024
1 parent d82b23c commit 01d3e70
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions backoff/_async.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# coding:utf-8
import datetime
import inspect
import functools
import asyncio
from datetime import timedelta
Expand All @@ -8,7 +9,7 @@


def _ensure_coroutine(coro_or_func):
if asyncio.iscoroutinefunction(coro_or_func):
if inspect.iscoroutinefunction(coro_or_func):
return coro_or_func
else:
@functools.wraps(coro_or_func)
Expand Down Expand Up @@ -47,10 +48,10 @@ def retry_predicate(target, wait_gen, predicate,
on_giveup = _ensure_coroutines(on_giveup)

# Easy to implement, please report if you need this.
assert not asyncio.iscoroutinefunction(max_tries)
assert not asyncio.iscoroutinefunction(jitter)
assert not inspect.iscoroutinefunction(max_tries)
assert not inspect.iscoroutinefunction(jitter)

assert asyncio.iscoroutinefunction(target)
assert inspect.iscoroutinefunction(target)

@functools.wraps(target)
async def retry(*args, **kwargs):
Expand Down Expand Up @@ -124,8 +125,8 @@ def retry_exception(target, wait_gen, exception,
giveup = _ensure_coroutine(giveup)

# Easy to implement, please report if you need this.
assert not asyncio.iscoroutinefunction(max_tries)
assert not asyncio.iscoroutinefunction(jitter)
assert not inspect.iscoroutinefunction(max_tries)
assert not inspect.iscoroutinefunction(jitter)

@functools.wraps(target)
async def retry(*args, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions backoff/_decorator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding:utf-8
import asyncio
import inspect
import logging
import operator
from typing import Any, Callable, Iterable, Optional, Type, Union
Expand Down Expand Up @@ -98,7 +98,7 @@ def decorate(target):
log_level=giveup_log_level
)

if asyncio.iscoroutinefunction(target):
if inspect.iscoroutinefunction(target):
retry = _async.retry_predicate
else:
retry = _sync.retry_predicate
Expand Down Expand Up @@ -198,7 +198,7 @@ def decorate(target):
log_level=giveup_log_level,
)

if asyncio.iscoroutinefunction(target):
if inspect.iscoroutinefunction(target):
retry = _async.retry_exception
else:
retry = _sync.retry_exception
Expand Down

0 comments on commit 01d3e70

Please sign in to comment.