Skip to content

fix: replace nest_asyncio for Python 3.14 compatibility#116

Open
lior-airis wants to merge 1 commit intodanielnsilva:masterfrom
lior-airis:fix/python-3.14-nest-asyncio
Open

fix: replace nest_asyncio for Python 3.14 compatibility#116
lior-airis wants to merge 1 commit intodanielnsilva:masterfrom
lior-airis:fix/python-3.14-nest-asyncio

Conversation

@lior-airis
Copy link

Summary

  • nest_asyncio is unmaintained and incompatible with Python 3.14
  • On Python 3.14, asyncio.current_task() returns None under nest_asyncio's patched event loop, causing anyio (used by httpcore/httpx) to crash with TypeError: cannot create weak reference to 'NoneType' object on every HTTP request
  • This broke 58 of 125 tests on the Python 3.14 CI matrix added in 93bc2ca
  • Replaced nest_asyncio.apply() + loop.run_until_complete() with a _run_async() helper that uses asyncio.run() directly when no event loop is running, or dispatches to a worker thread when called from within a running loop (preserving Jupyter notebook compatibility)
  • Same fix applied to PaginatedResults._get_next_page() which had the same pattern
  • Removed nest_asyncio from requirements.txt and setup.py

Test plan

  • All 123 tests pass on Python 3.14
  • All 123 tests pass on Python 3.12 (backward compatibility)
  • Jupyter use case preserved (thread-based fallback when event loop is already running)

🤖 Generated with Claude Code

…patibility

nest_asyncio is unmaintained and incompatible with Python 3.14: asyncio.current_task()
returns None under its patched event loop, causing anyio (used by httpcore/httpx) to crash
with "TypeError: cannot create weak reference to 'NoneType' object" on every HTTP request.

Replace nest_asyncio.apply() + loop.run_until_complete() with a _run_async() helper that
uses asyncio.run() directly when no event loop is running, or dispatches to a worker thread
when called from within a running loop (e.g. Jupyter notebooks).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
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