AnswerDotAI / AnswerDotAI/fastcore
`asyncio.iscoroutinefunction` is deprecated in Python 3.14, removed in 3.16
- Dominant language
- Jupyter Notebook
- Stars
- 1.1k
- Forks
- 295
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 7
Description
### 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
```console
$ 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
Contributor guide
Research direction
Read the two source notebooks, nbs/03_xtras.ipynb and nbs/03a_parallel.ipynb, alongside the generated call sites in fastcore/xtras.py and fastcore/parallel.py. Run the provided Python 3.14 import reproduction and relevant project tests; done means both call sites use the supported coroutine check and importing fastcore.xtras no longer emits the deprecation warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100