Skip to content

Commit 401709d

Browse files
Use inspect.iscoroutinefunction instead of asyncio.iscoroutinefunction
1 parent d82b23c commit 401709d

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

backoff/_async.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# coding:utf-8
22
import datetime
3+
import inspect
34
import functools
45
import asyncio
56
from datetime import timedelta
@@ -8,7 +9,7 @@
89

910

1011
def _ensure_coroutine(coro_or_func):
11-
if asyncio.iscoroutinefunction(coro_or_func):
12+
if inspect.iscoroutinefunction(coro_or_func):
1213
return coro_or_func
1314
else:
1415
@functools.wraps(coro_or_func)
@@ -47,10 +48,10 @@ def retry_predicate(target, wait_gen, predicate,
4748
on_giveup = _ensure_coroutines(on_giveup)
4849

4950
# Easy to implement, please report if you need this.
50-
assert not asyncio.iscoroutinefunction(max_tries)
51-
assert not asyncio.iscoroutinefunction(jitter)
51+
assert not inspect.iscoroutinefunction(max_tries)
52+
assert not inspect.iscoroutinefunction(jitter)
5253

53-
assert asyncio.iscoroutinefunction(target)
54+
assert inspect.iscoroutinefunction(target)
5455

5556
@functools.wraps(target)
5657
async def retry(*args, **kwargs):
@@ -124,8 +125,8 @@ def retry_exception(target, wait_gen, exception,
124125
giveup = _ensure_coroutine(giveup)
125126

126127
# Easy to implement, please report if you need this.
127-
assert not asyncio.iscoroutinefunction(max_tries)
128-
assert not asyncio.iscoroutinefunction(jitter)
128+
assert not inspect.iscoroutinefunction(max_tries)
129+
assert not inspect.iscoroutinefunction(jitter)
129130

130131
@functools.wraps(target)
131132
async def retry(*args, **kwargs):

backoff/_decorator.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding:utf-8
2-
import asyncio
2+
import inspect
33
import logging
44
import operator
55
from typing import Any, Callable, Iterable, Optional, Type, Union
@@ -98,7 +98,7 @@ def decorate(target):
9898
log_level=giveup_log_level
9999
)
100100

101-
if asyncio.iscoroutinefunction(target):
101+
if inspect.iscoroutinefunction(target):
102102
retry = _async.retry_predicate
103103
else:
104104
retry = _sync.retry_predicate
@@ -198,7 +198,7 @@ def decorate(target):
198198
log_level=giveup_log_level,
199199
)
200200

201-
if asyncio.iscoroutinefunction(target):
201+
if inspect.iscoroutinefunction(target):
202202
retry = _async.retry_exception
203203
else:
204204
retry = _sync.retry_exception

0 commit comments

Comments
 (0)