From c5490af213f6bdba2e17f829c46b81dddc3f2253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Tue, 19 Aug 2025 09:47:04 -0600 Subject: [PATCH] Use `inspect.iscoroutinefunction` instead of `asyncio.iscoroutinefunction` to avoid Python 3.14 deprecation warning --- backoff/_async.py | 13 +++++++------ backoff/_decorator.py | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/backoff/_async.py b/backoff/_async.py index 82fd477..b9e8d3e 100644 --- a/backoff/_async.py +++ b/backoff/_async.py @@ -2,13 +2,14 @@ import datetime import functools import asyncio +import inspect from datetime import timedelta from backoff._common import (_init_wait_gen, _maybe_call, _next_wait) 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) @@ -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): @@ -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): diff --git a/backoff/_decorator.py b/backoff/_decorator.py index 77ed8c2..ca5d0ff 100644 --- a/backoff/_decorator.py +++ b/backoff/_decorator.py @@ -1,5 +1,5 @@ # coding:utf-8 -import asyncio +import inspect import logging import operator from typing import Any, Callable, Iterable, Optional, Type, Union @@ -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 @@ -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