Skip to content

Conversation

@phillipuniverse
Copy link
Contributor

@phillipuniverse phillipuniverse commented Oct 17, 2025

Description

asyncio.iscoroutinefunction is officially deprecated in 3.14, inspect.iscoroutinefunction has been around since 3.5

Fixes #3879

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@phillipuniverse phillipuniverse force-pushed the deprecated-iscoroutinefunction branch from 3c95d5f to cb8c198 Compare October 17, 2025 13:57
@phillipuniverse phillipuniverse requested a review from a team as a code owner October 17, 2025 13:57
@phillipuniverse phillipuniverse force-pushed the deprecated-iscoroutinefunction branch from cb8c198 to 0d560f9 Compare October 17, 2025 14:38
from __future__ import annotations

from asyncio import iscoroutinefunction
from inspect import iscoroutinefunction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks something, could you please take a look at the failing tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup I’ll fix!

@xrmx xrmx moved this to Approved PRs that need fixes in @xrmx's Python PR digest Oct 31, 2025
@phillipuniverse
Copy link
Contributor Author

Hm the failing test is a bug in CPython where an AsyncMock fails inspect.iscoroutinefunction(), but asyncio.iscoroutinefunction() works. However, it appears that fix was only backported to Python 3.10+ (specifically 3.10.6+), so 3.9 still has the problem.

Here's a debug session that shows live variables and illustrates the problem:

image

I guess we could special case for Python 3.9, but I assume in the near term otel will drop Python 3.9 compatibility since it's EOL? The particularly annoying part is that this only shows up in AsyncMock on Python 3.9 and wouldn't show up in real runtime cases...

Our options as I see it:

  1. Special case this tests for aiokafka to work around this problem
  2. Don't accept this change until otel drops Python 3.9 code
  3. Add if sys.version_info < 3.9 to the iscoroutunction check to either use asyncio or inspect modules

I kind of think we should do (1)

@phillipuniverse
Copy link
Contributor Author

@xrmx I added what I think is a reasonable fix given the Python 3.9 status, LMK if you'd like a different change!

@phillipuniverse phillipuniverse requested a review from xrmx November 5, 2025 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs that need fixes

Development

Successfully merging this pull request may close these issues.

DeprecationWarning for asyncio.iscoroutinefunction on Python 3.14 HTTPX instrumentation

3 participants