Skip to content
Open
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
7 changes: 7 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ annotationlib
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
---------

Expand Down
3 changes: 2 additions & 1 deletion Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import traceback
import warnings
import weakref
import inspect

try:
import ssl
Expand Down Expand Up @@ -840,7 +841,7 @@ def call_soon(self, callback, *args, context=None):

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):
Expand Down
21 changes: 1 addition & 20 deletions Lib/asyncio/coroutines.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__all__ = 'iscoroutinefunction', 'iscoroutine'
__all__ = ('iscoroutine',)

import collections.abc
import inspect
Expand All @@ -13,25 +13,6 @@ def _is_debug_mode():
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)
Expand Down
3 changes: 2 additions & 1 deletion Lib/asyncio/unix_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sys
import threading
import warnings
import inspect

from . import base_events
from . import base_subprocess
Expand Down Expand Up @@ -94,7 +95,7 @@ def add_signal_handler(self, sig, callback, *args):
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)
Expand Down
5 changes: 0 additions & 5 deletions Lib/test/test_asyncio/test_pep492.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ def foo(): yield

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'
Expand Down
23 changes: 2 additions & 21 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import traceback
import types
import unittest
import inspect
from unittest import mock
from types import GenericAlias

Expand All @@ -20,7 +21,6 @@
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():
Expand Down Expand Up @@ -1940,30 +1940,11 @@ async def notmutch():
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))
Expand Down
8 changes: 0 additions & 8 deletions Lib/unittest/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ def reset_mock():


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()
Expand Down Expand Up @@ -2287,13 +2286,6 @@ class AsyncMockMixin(Base):

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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove deprecated :func:`!asyncio.iscoroutinefunction` function.
Loading