Use :meth:`annotationlib.ForwardRef.evaluate`
or :func:`typing.evaluate_forward_ref` instead.
+asyncio
+-------
+
+* The :func:`!asyncio.iscoroutinefunction`
+ which has been deprecated since Python 3.14.
+ Use :func:`inspect.iscoroutinefunction` instead.
+
functools
---------
import traceback
import warnings
import weakref
+import inspect
try:
import ssl
def _check_callback(self, callback, method):
if (coroutines.iscoroutine(callback) or
- coroutines._iscoroutinefunction(callback)):
+ inspect.iscoroutinefunction(callback)):
raise TypeError(
f"coroutines cannot be used with {method}()")
if not callable(callback):
-__all__ = 'iscoroutinefunction', 'iscoroutine'
+__all__ = ('iscoroutine',)
import collections.abc
import inspect
bool(os.environ.get('PYTHONASYNCIODEBUG')))
-# A marker for iscoroutinefunction.
-_is_coroutine = object()
-
-
-def iscoroutinefunction(func):
- import warnings
- """Return True if func is a decorated coroutine function."""
- warnings._deprecated("asyncio.iscoroutinefunction",
- f"{warnings._DEPRECATED_MSG}; "
- "use inspect.iscoroutinefunction() instead",
- remove=(3,16))
- return _iscoroutinefunction(func)
-
-
-def _iscoroutinefunction(func):
- return (inspect.iscoroutinefunction(func) or
- getattr(func, '_is_coroutine', None) is _is_coroutine)
-
-
# Prioritize native coroutine check to speed-up
# asyncio.iscoroutine.
_COROUTINE_TYPES = (types.CoroutineType, collections.abc.Coroutine)
import sys
import threading
import warnings
+import inspect
from . import base_events
from . import base_subprocess
Raise RuntimeError if there is a problem setting up the handler.
"""
if (coroutines.iscoroutine(callback) or
- coroutines._iscoroutinefunction(callback)):
+ inspect.iscoroutinefunction(callback)):
raise TypeError("coroutines cannot be used "
"with add_signal_handler()")
self._check_signal(sig)
self.assertFalse(asyncio.iscoroutine(foo()))
- def test_iscoroutinefunction(self):
- async def foo(): pass
- with self.assertWarns(DeprecationWarning):
- self.assertTrue(asyncio.iscoroutinefunction(foo))
-
def test_async_def_coroutines(self):
async def bar():
return 'spam'
import traceback
import types
import unittest
+import inspect
from unittest import mock
from types import GenericAlias
from test.test_asyncio import utils as test_utils
from test import support
from test.support.script_helper import assert_python_ok
-from test.support.warnings_helper import ignore_warnings
def tearDownModule():
self.assertFalse(task.cancelled())
self.assertIs(task.exception(), base_exc)
- @ignore_warnings(category=DeprecationWarning)
- def test_iscoroutinefunction(self):
- def fn():
- pass
-
- self.assertFalse(asyncio.iscoroutinefunction(fn))
-
- def fn1():
- yield
- self.assertFalse(asyncio.iscoroutinefunction(fn1))
-
- async def fn2():
- pass
- self.assertTrue(asyncio.iscoroutinefunction(fn2))
-
- self.assertFalse(asyncio.iscoroutinefunction(mock.Mock()))
- self.assertTrue(asyncio.iscoroutinefunction(mock.AsyncMock()))
-
- @ignore_warnings(category=DeprecationWarning)
def test_coroutine_non_gen_function(self):
async def func():
return 'test'
- self.assertTrue(asyncio.iscoroutinefunction(func))
+ self.assertTrue(inspect.iscoroutinefunction(func))
coro = func()
self.assertTrue(asyncio.iscoroutine(coro))
def _setup_async_mock(mock):
- mock._is_coroutine = asyncio.coroutines._is_coroutine
mock.await_count = 0
mock.await_args = None
mock.await_args_list = _CallList()
def __init__(self, /, *args, **kwargs):
super().__init__(*args, **kwargs)
- # iscoroutinefunction() checks _is_coroutine property to say if an
- # object is a coroutine. Without this check it looks to see if it is a
- # function/method, which in this case it is not (since it is an
- # AsyncMock).
- # It is set through __dict__ because when spec_set is True, this
- # attribute is likely undefined.
- self.__dict__['_is_coroutine'] = asyncio.coroutines._is_coroutine
self.__dict__['_mock_await_count'] = 0
self.__dict__['_mock_await_args'] = None
self.__dict__['_mock_await_args_list'] = _CallList()
--- /dev/null
+Remove deprecated :func:`!asyncio.iscoroutinefunction` function.