Visitar URL original
Migrate from asyncio.coroutines._is_coroutine to inspect.markcoroutinefunction() for Python 3.16+ compatibility · Issue #86 · teremterem/Promising · GitHub
Skip to content

Migrate from asyncio.coroutines._is_coroutine to inspect.markcoroutinefunction() for Python 3.16+ compatibility #86

Open

Description

@coderabbitai

Background

In promising/promising_function.py, PromisingFunction uses the following private asyncio marker to make asyncio.iscoroutinefunction() recognize it as a coroutine function:

_is_coroutine = asyncio.coroutines._is_coroutine

This is an internal, undocumented implementation detail of asyncio. While it works correctly today (Python 3.11–3.14), asyncio.iscoroutinefunction() has been deprecated as of Python 3.14 and is slated for removal in Python 3.16.

The stable, public replacement is inspect.markcoroutinefunction(), introduced in Python 3.12.

Suggested approach

Since the project currently supports Python 3.10+, a compatibility shim is needed:

import inspect
import sys

if sys.version_info >= (3, 12):
    inspect.markcoroutinefunction(PromisingFunction)
else:
    PromisingFunction._is_coroutine = asyncio.coroutines._is_coroutine

Or, equivalently, apply inspect.markcoroutinefunction() unconditionally when available, with the private sentinel as a fallback for Python < 3.12.

Impact

  • No current breakage — the existing code works on all supported Python versions.
  • Action needed before Python 3.16 support is required, when asyncio.iscoroutinefunction() and the _is_coroutine sentinel may be removed.

References

Activity

  1. teremterem commented on May 7, 2026

    @teremterem
    Owner

    ATTENTION! DOUBLE CHECK THE VERSION - AI KEEPS BLAMING 3.12 FOR EVERY BRAKING CHANGE WITHOUT PROOF

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions