Skip to content

Fix import on Python 3.14 after asyncio policy API changes - #164

Open
emirmrkaljevic wants to merge 1 commit into
python-trio:masterfrom
emirmrkaljevic:fix/py314-event-loop-policy
Open

emirmrkaljevic wants to merge 1 commit into
python-trio:masterfrom
emirmrkaljevic:fix/py314-event-loop-policy

Conversation

@emirmrkaljevic

Copy link
Copy Markdown

Fixes #160.

On Python 3.14, import trio_asyncio fails with AttributeError because
CPython renamed asyncio.events.BaseDefaultEventLoopPolicy to
_BaseDefaultEventLoopPolicy and removed asyncio.AbstractChildWatcher
(see also #152).

This PR resolves the policy and child-watcher base classes from whatever
the interpreter still provides, and uses the non-deprecated private
policy helpers on 3.14 when installing our loop policy at import time.
Older Python versions keep the previous behavior.

Note: with this change the import works on 3.14 and the new compat tests pass, but the full test suite on 3.14 still hangs in some aio_as_trio tests. That looks like a separate issue outside #160, so I left it out of this PR.

CPython 3.14 renamed BaseDefaultEventLoopPolicy to
_BaseDefaultEventLoopPolicy and removed AbstractChildWatcher, which
made `import trio_asyncio` raise AttributeError. Resolve the policy
and child-watcher bases based on what the interpreter provides, and
prefer the non-deprecated private policy helpers when installing our
loop policy at import time.

Fixes python-trio#160.
@emirmrkaljevic

Copy link
Copy Markdown
Author

The failing jobs look unrelated to this change. The pypy-3.9-nightly jobs fail during setup because there's no nightly PyPy 3.9 build available, and on Ubuntu 3.11/3.12 the only failure is CPython's own SslProtoHandshakeTests::test_check_hostname_requires_server_hostname (unraisable ResourceWarning during cleanup). #165, which touches different files, hits exactly the same failures; see the analysis there. Would a review be possible when you have time? Happy to adjust anything.

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.

Failing to import on Python >= 3.14

1 participant