Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc9d92c

Browse files
gh-122858: Deprecateasyncio.iscoroutinefunction (#122875)
Deprecate `asyncio.iscoroutinefunction` in favor of `inspect.iscoroutinefunction`.Co-authored-by: Kumar Aditya <kumaraditya@python.org>
1 parent3aaed08 commitbc9d92c

File tree

10 files changed

+27
-8
lines changed

10 files changed

+27
-8
lines changed

‎Doc/library/unittest.mock.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ object::
882882
call is an awaitable.
883883

884884
>>>mock= AsyncMock()
885-
>>>asyncio.iscoroutinefunction(mock)
885+
>>>inspect.iscoroutinefunction(mock)
886886
True
887887
>>>inspect.isawaitable(mock())# doctest: +SKIP
888888
True

‎Doc/whatsnew/3.14.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,11 @@ Deprecated
434434
:c:macro:`!isfinite` available from:file:`math.h`
435435
since C99. (Contributed by Sergey B Kirpichev in:gh:`119613`.)
436436

437+
*:func:`!asyncio.iscoroutinefunction` is deprecated
438+
and will be removed in Python 3.16,
439+
use:func:`inspect.iscoroutinefunction` instead.
440+
(Contributed by Jiahao Li and Kumar Aditya in:gh:`122875`.)
441+
437442
.. Add deprecations above alphabetically, not here at the end.
438443
439444
..include::../deprecations/c-api-pending-removal-in-3.15.rst

‎Lib/asyncio/base_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ def call_soon(self, callback, *args, context=None):
837837

838838
def_check_callback(self,callback,method):
839839
if (coroutines.iscoroutine(callback)or
840-
coroutines.iscoroutinefunction(callback)):
840+
coroutines._iscoroutinefunction(callback)):
841841
raiseTypeError(
842842
f"coroutines cannot be used with{method}()")
843843
ifnotcallable(callback):

‎Lib/asyncio/coroutines.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@ def _is_debug_mode():
1818

1919

2020
defiscoroutinefunction(func):
21+
importwarnings
2122
"""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):
2231
return (inspect.iscoroutinefunction(func)or
2332
getattr(func,'_is_coroutine',None)is_is_coroutine)
2433

‎Lib/asyncio/unix_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def add_signal_handler(self, sig, callback, *args):
9595
Raise RuntimeError if there is a problem setting up the handler.
9696
"""
9797
if (coroutines.iscoroutine(callback)or
98-
coroutines.iscoroutinefunction(callback)):
98+
coroutines._iscoroutinefunction(callback)):
9999
raiseTypeError("coroutines cannot be used "
100100
"with add_signal_handler()")
101101
self._check_signal(sig)

‎Lib/test/test_asyncio/test_pep492.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ def foo(): yield
124124

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

127-
128127
deftest_iscoroutinefunction(self):
129128
asyncdeffoo():pass
130-
self.assertTrue(asyncio.iscoroutinefunction(foo))
129+
withself.assertWarns(DeprecationWarning):
130+
self.assertTrue(asyncio.iscoroutinefunction(foo))
131131

132132
deftest_async_def_coroutines(self):
133133
asyncdefbar():

‎Lib/test/test_asyncio/test_tasks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
fromtest.test_asyncioimportutilsastest_utils
2121
fromtestimportsupport
2222
fromtest.support.script_helperimportassert_python_ok
23+
fromtest.support.warnings_helperimportignore_warnings
2324

2425

2526
deftearDownModule():
@@ -1939,6 +1940,7 @@ async def notmutch():
19391940
self.assertFalse(task.cancelled())
19401941
self.assertIs(task.exception(),base_exc)
19411942

1943+
@ignore_warnings(category=DeprecationWarning)
19421944
deftest_iscoroutinefunction(self):
19431945
deffn():
19441946
pass
@@ -1956,6 +1958,7 @@ async def fn2():
19561958
self.assertFalse(asyncio.iscoroutinefunction(mock.Mock()))
19571959
self.assertTrue(asyncio.iscoroutinefunction(mock.AsyncMock()))
19581960

1961+
@ignore_warnings(category=DeprecationWarning)
19591962
deftest_coroutine_non_gen_function(self):
19601963
asyncdeffunc():
19611964
return'test'

‎Lib/test/test_unittest/testmock/testmagicmethods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
importmath
22
importunittest
33
importos
4-
fromasyncioimportiscoroutinefunction
4+
frominspectimportiscoroutinefunction
55
fromunittest.mockimportAsyncMock,Mock,MagicMock,_magics
66

77

‎Lib/unittest/mock.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
importsys
3333
importbuiltins
3434
importpkgutil
35-
fromasyncioimportiscoroutinefunction
35+
frominspectimportiscoroutinefunction
3636
importthreading
3737
fromtypesimportCodeType,ModuleType,MethodType
3838
fromunittest.utilimportsafe_repr
@@ -2456,7 +2456,7 @@ class AsyncMock(AsyncMockMixin, AsyncMagicMixin, Mock):
24562456
recognized as an async function, and the result of a call is an awaitable:
24572457
24582458
>>> mock = AsyncMock()
2459-
>>> iscoroutinefunction(mock)
2459+
>>>inspect.iscoroutinefunction(mock)
24602460
True
24612461
>>> inspect.isawaitable(mock())
24622462
True
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Deprecate:func:`!asyncio.iscoroutinefunction` in favor of
2+
:func:`inspect.iscoroutinefunction`.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp