Visitar URL original
Use inspect.iscoroutinefunction instead of the deprecated asyncio.iscoroutinefunction by maoxor · Pull Request #5389 · python-telegram-bot/python-telegram-bot · GitHub
Skip to content

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

Open
maoxor wants to merge 1 commit into
python-telegram-bot:masterfrom
maoxor:inspect-iscoroutinefunction
Open

maoxor wants to merge 1 commit into
python-telegram-bot:masterfrom
maoxor:inspect-iscoroutinefunction

Conversation

@maoxor

@maoxor maoxor commented Oct 29, 2026 •

Copy link
Copy Markdown

Closes #5388.

CallbackQueryHandler (with a callable pattern) and Updater.start_polling (with an error_callback) use asyncio.iscoroutinefunction, which emits a DeprecationWarning on Python 3.14+ and is slated for removal in 3.16. This switches them, and the call_after test helper, to inspect.iscoroutinefunction.

The swap doesn't change behaviour on the supported versions. On CPython 3.11, 3.12, 3.13, 3.14 and 3.15, both functions return the same result for async def, plain functions, lambdas, functools.partial of each, AsyncMock(), MagicMock(), a bound async method and an instance with an async __call__. (The difference with AsyncMock that came up elsewhere only affects 3.10, which PTB no longer supports.)

What I ran:

  • test_callbackqueryhandler.py, test_updater.py, test_application.py and test_baseupdateprocessor.py (the last two use call_after), with TEST_WITH_OPT_DEPS=true:
    • 3.15.0 with -W "error:'asyncio.iscoroutinefunction':DeprecationWarning": 29 + 72 + 162 + 9 passed. On master, that flag makes 4 tests in test_callbackqueryhandler.py and 6 in test_updater.py fail.
    • 3.11: same results.
  • Ruff 0.16.8 (check + format), mypy 1.20.2 on the two changed modules, and pylint 4.1.3 (10.00/10).

I didn't run the rest of the suite or the tests that need bot tokens.

Check-list for PRs

  • Added .. versionadded:: NEXT.VERSION etc. (not needed: no user-facing change)
  • Created new or adapted existing unit tests (existing tests cover both checks; the test helper is updated)
  • Documented code changes according to the CSI standard (no new code to document)
  • Added myself alphabetically to AUTHORS.rst (optional)
  • Added new classes & modules to the docs and all suitable __all__s (not applicable)
  • Checked the Stability Policy in case of deprecations or changes to documented behavior (no behaviour change)

asyncio.iscoroutinefunction is deprecated since Python 3.14 and slated
for removal in 3.16. CallbackQueryHandler (callable pattern) and
Updater.start_polling (error_callback) called it, emitting a
DeprecationWarning on 3.14+. inspect.iscoroutinefunction gives the same
results on the supported Python versions (3.11+).

Closes python-telegram-bot#5388
@maoxor
maoxor force-pushed the inspect-iscoroutinefunction branch from d0633d1 to e4a7433 Compare October 29, 2026 16:00

This branch has not been deployed

No deployments
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.

asyncio.iscoroutinefunction is deprecated since Python 3.14 (removed in 3.16)

1 participant