diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5e7a8b6..c3baa7d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,7 +40,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] steps: - uses: actions/checkout@v5 diff --git a/nest_asyncio.py b/nest_asyncio.py index 47f0d59..770ad3d 100644 --- a/nest_asyncio.py +++ b/nest_asyncio.py @@ -39,6 +39,14 @@ def _get_event_loop(stacklevel=3): # noqa: ARG001 loop = events.get_event_loop_policy().get_event_loop() return loop + # We need to patch this since 3.14 due to: + # https://github.com/python/cpython/pull/129899 + def current_task(loop=None): + """Return a currently executed task.""" + if loop is None: + loop = asyncio.events.get_running_loop() + return asyncio.tasks._current_tasks.get(loop) + # Use module level _current_tasks, all_tasks and patch run method. if hasattr(asyncio, '_nest_patched'): return @@ -47,6 +55,8 @@ def _get_event_loop(stacklevel=3): # noqa: ARG001 asyncio.Future = asyncio.futures._CFuture = asyncio.futures.Future = asyncio.futures._PyFuture events._get_event_loop = events.get_event_loop = asyncio.get_event_loop = _get_event_loop asyncio.run = run + if sys.version_info >= (3, 14, 0): + asyncio.tasks.current_task = current_task asyncio._nest_patched = True diff --git a/pyproject.toml b/pyproject.toml index 97c39e8..db62c17 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", "Programming Language :: Python :: 3 :: Only", "Framework :: AsyncIO", ]