Skip to content

Use iscoroutinefunction from inspect not asyncio#359

Open
AdamWill wants to merge 1 commit into
pydanny:mainfrom
AdamWill:inspect-iscoroutinefunc
Open

Use iscoroutinefunction from inspect not asyncio#359
AdamWill wants to merge 1 commit into
pydanny:mainfrom
AdamWill:inspect-iscoroutinefunc

Conversation

@AdamWill

@AdamWill AdamWill commented Nov 5, 2024

Copy link
Copy Markdown
Contributor

Python 3.14 will deprecate asyncio.iscoroutinefunction: python/cpython#122875

inspect.iscoroutinefunction exists since 3.5 and our baseline is 3.8, so we can just use it unconditionally.

Using a wrapper with @asyncio.coroutine in get wasn't necessary (the future from asyncio.ensure_future is awaitable, and the wrapper doesn't do anything asynchronous), so the logic can be simplified to just call asyncio.ensure_future (to schedule the task and store the result when it's available).

Python 3.14 will deprecate asyncio.iscoroutinefunction:
python/cpython#122875

inspect.iscoroutinefunction exists since 3.5 and our baseline
is 3.8, so we can just use it unconditionally.

Using a wrapper with @asyncio.coroutine in __get__ wasn't
necessary (the future from asyncio.ensure_future is awaitable,
and the wrapper doesn't do anything asynchronous), so the
logic can be simplified to just call asyncio.ensure_future
(to schedule the task and store the result when it's
available).
@AdamWill

AdamWill commented Nov 5, 2024

Copy link
Copy Markdown
Contributor Author

This is a rebase of #267 , but it turns out to be much simpler against 2.0.1. Skipping test_coroutine_cached_property.py as the original did no longer appears to be necessary - arguably that test could now be removed as we're targeting a 3.8 baseline, but it seems like that could be a separate PR. @encukou for info, I've kept you as the author of this but can change it to me if you don't want your name on it any more :)

@nguettler

Copy link
Copy Markdown

Pls, let's merge this. Python 3.14 is out

@AdamWill

AdamWill commented Mar 4, 2026

Copy link
Copy Markdown
Contributor Author

Just in case folks don't know, the standard library functools has a cached_property implementation since 3.8. So if your baseline is 3.8 or higher you can just switch to that and forget about this problem.

If you still have < 3.8 as a baseline for some reason (koff koff RHEL), you can do:

try:
    # Python >= 3.8
    from functools import cached_property
except ImportError:
    # Python < 3.8
    from cached_property import cached_property

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.

3 participants