Skip to content

Commit

Permalink
Add python 3.12 support
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Oct 10, 2023
1 parent 8284fc3 commit 1f90506
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 42 deletions.
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())

0 comments on commit 1f90506

Please sign in to comment.