Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python 3.12 support #367

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8", "3.11"]
python-version: ["3.8", "3.12"]
include:
- os: windows-latest
python-version: "3.9"
- os: ubuntu-latest
python-version: "pypy-3.8"
python-version: "3.11"
- os: ubuntu-latest
python-version: "pypy-3.9"
- os: macos-latest
python-version: "3.10"
steps:
Expand Down
17 changes: 11 additions & 6 deletions jupyter_core/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,17 @@ def wrapped(*args: Any, **kwargs: Any) -> Any:
pass

# Run the loop for this thread.
try:
loop = asyncio.get_event_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
return loop.run_until_complete(inner)
# In Python 3.12, a deprecation warning is raised, which
# may later turn into a RuntimeError. We handle both
# cases.
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
try:
loop = asyncio.get_event_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
return loop.run_until_complete(inner)

wrapped.__doc__ = coro.__doc__
return wrapped
Expand Down
34 changes: 0 additions & 34 deletions tests/test_async.py

This file was deleted.

56 changes: 56 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Tests for utils"""

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

import asyncio
import os
import tempfile

import pytest

from jupyter_core.utils import deprecation, ensure_async, ensure_dir_exists, run_sync


def test_ensure_dir_exists():
with tempfile.TemporaryDirectory() as td:
ensure_dir_exists(td)
ensure_dir_exists(os.path.join(str(td), "foo"), 0o777)


def test_deprecation():
with pytest.deprecated_call():
deprecation("foo")


async def afunc():
return "afunc"


def func():
return "func"


sync_afunc = run_sync(afunc)


def test_run_sync():
async def foo():
return 1

foo_sync = run_sync(foo)
assert foo_sync() == 1
assert foo_sync() == 1

asyncio.set_event_loop(None)
assert foo_sync() == 1

asyncio.run(foo())


def test_ensure_async():
async def main():
assert await ensure_async(afunc()) == "afunc"
assert await ensure_async(func()) == "func"

asyncio.run(main())
Loading