Skip to content

Commit

Permalink
Fix asyncio.iscoroutinefunction DeprecationWarning in Python 3.14.0a1
Browse files Browse the repository at this point in the history
DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead

Signed-off-by: Zac Medico <zmedico@gentoo.org>
  • Loading branch information
zmedico committed Oct 22, 2024
1 parent d335265 commit 7218c9c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/portage/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
from functools import lru_cache, partial
from typing import Any, Optional, Callable, Union

try:
from inspect import iscoroutinefunction
except ImportError:
iscoroutinefunction = _asyncio.iscoroutinefunction

from portage import os
from portage import _encodings
from portage import _unicode_encode
Expand Down Expand Up @@ -203,7 +208,7 @@ def atexit_register(func, *args, **kargs):
manually by calling the run_exitfuncs() function in this module."""
# The internal asyncio wrapper module would trigger a circular import
# if used here.
if _asyncio.iscoroutinefunction(func):
if iscoroutinefunction(func):
# Add this coroutine function to the exit handlers for the loop
# which is associated with the current thread.
global_event_loop()._coroutine_exithandlers.append((func, args, kargs))
Expand Down
6 changes: 5 additions & 1 deletion lib/portage/util/futures/_asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@
FIRST_EXCEPTION,
Future,
InvalidStateError,
iscoroutinefunction,
Lock as _Lock,
shield,
TimeoutError,
wait_for,
)

try:
from inspect import iscoroutinefunction
except ImportError:
iscoroutinefunction = _asyncio.iscoroutinefunction

import threading
from typing import Optional

Expand Down

0 comments on commit 7218c9c

Please sign in to comment.