Skip to content

asyncio.iscoroutinefunction is deprecated in Python 3.14, removed in 3.16 #933

Description

@shadowhand

Summary

fastcore calls asyncio.iscoroutinefunction() in two places. Python 3.14 deprecates it and schedules removal for 3.16, so importing fastcore on 3.14 emits a DeprecationWarning, and on 3.16 these call sites will raise AttributeError.

Reproducing

$ python -c "import fastcore.xtras"
.../fastcore/xtras.py:1239: DeprecationWarning: 'asyncio.iscoroutinefunction'
is deprecated and slated for removal in Python 3.16; use
inspect.iscoroutinefunction() instead
    return async_wrapper if asyncio.iscoroutinefunction(func) else wrapper

The xtras one fires on import, so it surfaces for anyone importing fastcore (or fasthtml) at all — including in test suites that treat warnings as errors.

Call sites

Since these are nbdev-generated, the fix belongs in the notebooks:

Generated Source
fastcore/xtras.py:1239 (flexicache) nbs/03_xtras.ipynb
fastcore/parallel.py:162 (parallel_async) nbs/03a_parallel.ipynb

Both are current as of 2.2.22.

Suggested fix

Swap to inspect.iscoroutinefunction, which CPython names as the replacement. I checked the substitution on 3.14.5 against the shapes these call sites see:

callable asyncio. inspect.
async def True True
plain def False False
functools.partial(async_fn) True True
@inspect.markcoroutinefunction True True

inspect.iscoroutinefunction has existed since 3.5 and has unwrapped functools.partial since 3.8, so this is safe across the >=3.10 range in settings.ini with no version guard.

One caveat for your judgement: the two differ for callables carrying asyncio's private _is_coroutine marker, which inspect does not consult. That's a private API, so it seems unlikely to matter here, but you'd know better than I would whether anything relies on it.

Environment

fastcore 2.2.13 and 2.2.22 · Python 3.14.5 · macOS and Ubuntu

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions