Skip to content

Commit bfc8f79

Browse files
committed
gh-149600: Remove deprecated asyncio.iscoroutinefunction function
1 parent 46a2c11 commit bfc8f79

8 files changed

Lines changed: 15 additions & 55 deletions

File tree

Doc/whatsnew/3.16.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ annotationlib
114114
Use :meth:`annotationlib.ForwardRef.evaluate`
115115
or :func:`typing.evaluate_forward_ref` instead.
116116

117+
asyncio
118+
-------
119+
120+
* The :func:`!asyncio.iscoroutinefunction`
121+
which has been deprecated since Python 3.14.
122+
Use :func:`inspect.iscoroutinefunction` instead.
123+
117124
functools
118125
---------
119126

Lib/asyncio/base_events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import traceback
3232
import warnings
3333
import weakref
34+
import inspect
3435

3536
try:
3637
import ssl
@@ -840,7 +841,7 @@ def call_soon(self, callback, *args, context=None):
840841

841842
def _check_callback(self, callback, method):
842843
if (coroutines.iscoroutine(callback) or
843-
coroutines._iscoroutinefunction(callback)):
844+
inspect.iscoroutinefunction(callback)):
844845
raise TypeError(
845846
f"coroutines cannot be used with {method}()")
846847
if not callable(callback):

Lib/asyncio/coroutines.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__all__ = 'iscoroutinefunction', 'iscoroutine'
1+
__all__ = ('iscoroutine',)
22

33
import collections.abc
44
import inspect
@@ -13,25 +13,6 @@ def _is_debug_mode():
1313
bool(os.environ.get('PYTHONASYNCIODEBUG')))
1414

1515

16-
# A marker for iscoroutinefunction.
17-
_is_coroutine = object()
18-
19-
20-
def iscoroutinefunction(func):
21-
import warnings
22-
"""Return True if func is a decorated coroutine function."""
23-
warnings._deprecated("asyncio.iscoroutinefunction",
24-
f"{warnings._DEPRECATED_MSG}; "
25-
"use inspect.iscoroutinefunction() instead",
26-
remove=(3,16))
27-
return _iscoroutinefunction(func)
28-
29-
30-
def _iscoroutinefunction(func):
31-
return (inspect.iscoroutinefunction(func) or
32-
getattr(func, '_is_coroutine', None) is _is_coroutine)
33-
34-
3516
# Prioritize native coroutine check to speed-up
3617
# asyncio.iscoroutine.
3718
_COROUTINE_TYPES = (types.CoroutineType, collections.abc.Coroutine)

Lib/asyncio/unix_events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import sys
1313
import threading
1414
import warnings
15+
import inspect
1516

1617
from . import base_events
1718
from . import base_subprocess
@@ -94,7 +95,7 @@ def add_signal_handler(self, sig, callback, *args):
9495
Raise RuntimeError if there is a problem setting up the handler.
9596
"""
9697
if (coroutines.iscoroutine(callback) or
97-
coroutines._iscoroutinefunction(callback)):
98+
inspect.iscoroutinefunction(callback)):
9899
raise TypeError("coroutines cannot be used "
99100
"with add_signal_handler()")
100101
self._check_signal(sig)

Lib/test/test_asyncio/test_pep492.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@ def foo(): yield
124124

125125
self.assertFalse(asyncio.iscoroutine(foo()))
126126

127-
def test_iscoroutinefunction(self):
128-
async def foo(): pass
129-
with self.assertWarns(DeprecationWarning):
130-
self.assertTrue(asyncio.iscoroutinefunction(foo))
131-
132127
def test_async_def_coroutines(self):
133128
async def bar():
134129
return 'spam'

Lib/test/test_asyncio/test_tasks.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import traceback
1212
import types
1313
import unittest
14+
import inspect
1415
from unittest import mock
1516
from types import GenericAlias
1617

@@ -1940,30 +1941,11 @@ async def notmutch():
19401941
self.assertFalse(task.cancelled())
19411942
self.assertIs(task.exception(), base_exc)
19421943

1943-
@ignore_warnings(category=DeprecationWarning)
1944-
def test_iscoroutinefunction(self):
1945-
def fn():
1946-
pass
1947-
1948-
self.assertFalse(asyncio.iscoroutinefunction(fn))
1949-
1950-
def fn1():
1951-
yield
1952-
self.assertFalse(asyncio.iscoroutinefunction(fn1))
1953-
1954-
async def fn2():
1955-
pass
1956-
self.assertTrue(asyncio.iscoroutinefunction(fn2))
1957-
1958-
self.assertFalse(asyncio.iscoroutinefunction(mock.Mock()))
1959-
self.assertTrue(asyncio.iscoroutinefunction(mock.AsyncMock()))
1960-
1961-
@ignore_warnings(category=DeprecationWarning)
19621944
def test_coroutine_non_gen_function(self):
19631945
async def func():
19641946
return 'test'
19651947

1966-
self.assertTrue(asyncio.iscoroutinefunction(func))
1948+
self.assertTrue(inspect.iscoroutinefunction(func))
19671949

19681950
coro = func()
19691951
self.assertTrue(asyncio.iscoroutine(coro))

Lib/unittest/mock.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ def reset_mock():
281281

282282

283283
def _setup_async_mock(mock):
284-
mock._is_coroutine = asyncio.coroutines._is_coroutine
285284
mock.await_count = 0
286285
mock.await_args = None
287286
mock.await_args_list = _CallList()
@@ -2287,13 +2286,6 @@ class AsyncMockMixin(Base):
22872286

22882287
def __init__(self, /, *args, **kwargs):
22892288
super().__init__(*args, **kwargs)
2290-
# iscoroutinefunction() checks _is_coroutine property to say if an
2291-
# object is a coroutine. Without this check it looks to see if it is a
2292-
# function/method, which in this case it is not (since it is an
2293-
# AsyncMock).
2294-
# It is set through __dict__ because when spec_set is True, this
2295-
# attribute is likely undefined.
2296-
self.__dict__['_is_coroutine'] = asyncio.coroutines._is_coroutine
22972289
self.__dict__['_mock_await_count'] = 0
22982290
self.__dict__['_mock_await_args'] = None
22992291
self.__dict__['_mock_await_args_list'] = _CallList()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove deprecated :func:`!asyncio.iscoroutinefunction` function.

0 commit comments

Comments
 (0)