Skip to content

Commit 1fd46f2

Browse files
committed
🔧 Update async_eval version
1 parent 261b955 commit 1fd46f2

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

helpers/poetry.lock

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/uriyyo/evaluate_async_code/AsyncPyDebugUtils.kt

+22-5
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,17 @@ from asyncio import AbstractEventLoop
280280
from typing import Any, Callable
281281
282282
try:
283-
from nest_asyncio import _patch_loop, apply
284-
except ImportError: # pragma: no cover
283+
_ = _patch_loop # noqa
284+
_ = apply # noqa
285+
except NameError:
286+
try:
287+
from nest_asyncio import _patch_loop, apply
288+
except ImportError: # pragma: no cover
285289
286-
def _noop(*args: Any, **kwargs: Any) -> None:
287-
pass
290+
def _noop(*args: Any, **kwargs: Any) -> None:
291+
pass
288292
289-
_patch_loop = apply = _noop
293+
_patch_loop = apply = _noop
290294
291295
292296
def is_async_debug_available(loop: Any = None) -> bool:
@@ -359,6 +363,17 @@ except ImportError: # pragma: no cover
359363
ctypes.pythonapi.PyFrame_LocalsToFast(ctypes.py_object(frame), ctypes.c_int(1))
360364
361365
366+
try:
367+
_ = apply # noqa
368+
except NameError:
369+
try:
370+
from nest_asyncio import apply
371+
except ImportError:
372+
373+
def apply(_: Any = None) -> None:
374+
pass
375+
376+
362377
_ASYNC_EVAL_CODE_TEMPLATE = textwrap.dedent(
363378
'''\
364379
__locals__ = locals()
@@ -517,6 +532,8 @@ def is_async_code(code: str) -> bool:
517532
518533
# async equivalent of builtin eval function
519534
def async_eval(code: str, _globals: Optional[dict] = None, _locals: Optional[dict] = None) -> Any:
535+
apply() # double check that loop is patched
536+
520537
caller: types.FrameType = inspect.currentframe().f_back # type: ignore
521538
522539
if _locals is None:

0 commit comments

Comments
 (0)