Skip to content

Use inspect.iscoroutinefunction instead of the deprecated asyncio.iscoroutinefunction - #951

Closed
PiotrCzapla wants to merge 1 commit into
AnswerDotAI:mainfrom
PiotrCzapla:fastcore-iscoroutinefunction
Closed

PiotrCzapla wants to merge 1 commit into
AnswerDotAI:mainfrom
PiotrCzapla:fastcore-iscoroutinefunction

Conversation

@PiotrCzapla

Copy link
Copy Markdown

This addresses a warning that iscoroutinefunction has moved to inspect since 3.5 when async def was introduced. Using the asyncio made sense up until Python 3.11 which removes the @asyncio.coroutine decorator the only difference between old asyncio and inspect versions.

Claude note below:
Python 3.14 deprecates asyncio.iscoroutinefunction, and 3.16 removes it, so every call emits a DeprecationWarning. This switches fastcore's three uses to inspect.iscoroutinefunction: is_async_callable (aio), parallel_async_gen (parallel) and flexicache (xtras).

The two return the same result for plain coroutine functions, functools.partial of them and unittest.mock.AsyncMock, checked on Python 3.10, 3.12 and 3.13. The asyncio version also accepted the @asyncio.coroutine decorator, which Python 3.11 removed.

Tests: nbdev-test passes for 03c_aio and 03a_parallel on Python 3.14. 03_xtras stops at an unrelated cell, Person(name="Bob") raising TypeError, which fails the same way on main under 3.14.

…oroutinefunction

This addresses a warning that `iscoroutinefunction` has moved to `inspect` since 3.5 when `async def` was introduced. Using the `asyncio` made sense up until Python 3.11 which removes the `@asyncio.coroutine` decorator the only difference between old asyncio and inspect versions.

Claude note below:
Python 3.14 deprecates `asyncio.iscoroutinefunction`, and 3.16 removes it, so every call emits a `DeprecationWarning`. This switches fastcore's three uses to `inspect.iscoroutinefunction`: `is_async_callable` (aio), `parallel_async_gen` (parallel) and `flexicache` (xtras).

The two return the same result for plain coroutine functions, `functools.partial` of them and `unittest.mock.AsyncMock`, checked on Python 3.10, 3.12 and 3.13. The asyncio version also accepted the `@asyncio.coroutine` decorator, which Python 3.11 removed.

Tests: `nbdev-test` passes for `03c_aio` and `03a_parallel` on Python 3.14. `03_xtras` stops at an unrelated cell, `Person(name="Bob")` raising `TypeError`, which fails the same way on `main` under 3.14.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PiotrCzapla
PiotrCzapla deleted the fastcore-iscoroutinefunction branch October 19, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant