Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions fastapi_utils/tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import asyncio
import inspect
import logging
import warnings
from functools import wraps
Expand All @@ -19,15 +20,15 @@


async def _handle_func(func: NoArgsNoReturnAnyFuncT) -> None:
if asyncio.iscoroutinefunction(func):
if inspect.iscoroutinefunction(func):
await func()
else:
await run_in_threadpool(func)


async def _handle_exc(exc: Exception, on_exception: ExcArgNoReturnAnyFuncT | None) -> None:
if on_exception:
if asyncio.iscoroutinefunction(on_exception):
if inspect.iscoroutinefunction(on_exception):
await on_exception(exc)
else:
await run_in_threadpool(on_exception, exc)
Expand Down
20 changes: 20 additions & 0 deletions tests/test_tasks_iscoroutine_regression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Regression tests for issue #373.

The tasks module must use ``inspect.iscoroutinefunction`` rather than
``asyncio.iscoroutinefunction``, which is deprecated in Python 3.14
(``DeprecationWarning``) and scheduled for removal.

See: https://github.com/fastapiutils/fastapi-utils/issues/373
"""

from __future__ import annotations

import inspect

from fastapi_utils import tasks as tasks_module


def test_tasks_module_uses_inspect_iscoroutinefunction() -> None:
source = inspect.getsource(tasks_module)
assert "asyncio.iscoroutinefunction" not in source
assert "inspect.iscoroutinefunction" in source