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

gh-122858: Deprecateasyncio.iscoroutinefunction#122875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kumaraditya303 merged 16 commits intopython:mainfromWulian233:asyncio
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
16 commits
Select commitHold shift + click to select a range
1036f01
Deprecate :func:`asyncio.iscoroutinefunction` in favor of :func:`insp…
Wulian233Aug 10, 2024
228d2f2
gh:`122875`
Wulian233Aug 10, 2024
c831bb1
typo
Wulian233Aug 10, 2024
d48ed66
fix
Wulian233Aug 10, 2024
7aae62f
fix
Wulian233Aug 10, 2024
ae0b8f0
fix
Wulian233Aug 10, 2024
62b8d3b
Apply suggestions from code review
kumaraditya303Aug 10, 2024
750d294
use coroutines.iscoroutine and coroutines._iscoroutinefunction
Wulian233Aug 10, 2024
78655aa
import coroutines
Wulian233Aug 10, 2024
58013d5
Update Misc/NEWS.d/next/Library/2024-08-10-10-21-44.gh-issue-122858.Z…
kumaraditya303Aug 10, 2024
1be0d66
from inspect import iscoroutinefunction
Wulian233Aug 10, 2024
840191d
remove
Wulian233Aug 10, 2024
e0f0272
test_pep492.py
Wulian233Aug 10, 2024
231cfb3
finish
Wulian233Aug 10, 2024
c1f2743
test_pep492
Wulian233Aug 11, 2024
d8c86c6
fix tests
kumaraditya303Aug 11, 2024
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
2 changes: 1 addition & 1 deletionDoc/library/unittest.mock.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -882,7 +882,7 @@ object::
call is an awaitable.

>>> mock = AsyncMock()
>>>asyncio.iscoroutinefunction(mock)
>>>inspect.iscoroutinefunction(mock)
True
>>> inspect.isawaitable(mock()) # doctest: +SKIP
True
Expand Down
5 changes: 5 additions & 0 deletionsDoc/whatsnew/3.14.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -425,6 +425,11 @@ Deprecated
:c:macro:`!isfinite` available from :file:`math.h`
since C99. (Contributed by Sergey B Kirpichev in :gh:`119613`.)

* :func:`!asyncio.iscoroutinefunction` is deprecated
and will be removed in Python 3.16,
use :func:`inspect.iscoroutinefunction` instead.
(Contributed by Jiahao Li and Kumar Aditya in :gh:`122875`.)

.. Add deprecations above alphabetically, not here at the end.

.. include:: ../deprecations/c-api-pending-removal-in-3.15.rst
Expand Down
2 changes: 1 addition & 1 deletionLib/asyncio/base_events.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -837,7 +837,7 @@ def call_soon(self, callback, *args, context=None):

def _check_callback(self, callback, method):
if (coroutines.iscoroutine(callback) or
coroutines.iscoroutinefunction(callback)):
coroutines._iscoroutinefunction(callback)):
raise TypeError(
f"coroutines cannot be used with {method}()")
if not callable(callback):
Expand Down
9 changes: 9 additions & 0 deletionsLib/asyncio/coroutines.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,16 @@ def _is_debug_mode():


defiscoroutinefunction(func):
importwarnings
"""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)

Expand Down
2 changes: 1 addition & 1 deletionLib/asyncio/unix_events.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -95,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)):
coroutines._iscoroutinefunction(callback)):
raise TypeError("coroutines cannot be used "
"with add_signal_handler()")
self._check_signal(sig)
Expand Down
4 changes: 2 additions & 2 deletionsLib/test/test_asyncio/test_pep492.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,10 +124,10 @@ def foo(): yield

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


def test_iscoroutinefunction(self):
async def foo(): pass
self.assertTrue(asyncio.iscoroutinefunction(foo))
with self.assertWarns(DeprecationWarning):
self.assertTrue(asyncio.iscoroutinefunction(foo))

def test_async_def_coroutines(self):
async def bar():
Expand Down
3 changes: 3 additions & 0 deletionsLib/test/test_asyncio/test_tasks.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,7 @@
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 DownExpand Up@@ -1939,6 +1940,7 @@ async def notmutch():
self.assertFalse(task.cancelled())
self.assertIs(task.exception(), base_exc)

@ignore_warnings(category=DeprecationWarning)
def test_iscoroutinefunction(self):
def fn():
pass
Expand All@@ -1956,6 +1958,7 @@ async def 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'
Expand Down
2 changes: 1 addition & 1 deletionLib/test/test_unittest/testmock/testmagicmethods.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import math
import unittest
import os
fromasyncio import iscoroutinefunction
frominspect import iscoroutinefunction
from unittest.mock import AsyncMock, Mock, MagicMock, _magics


Expand Down
4 changes: 2 additions & 2 deletionsLib/unittest/mock.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,7 +32,7 @@
import sys
import builtins
import pkgutil
fromasyncio import iscoroutinefunction
frominspect import iscoroutinefunction
import threading
from types import CodeType, ModuleType, MethodType
from unittest.util import safe_repr
Expand DownExpand Up@@ -2456,7 +2456,7 @@ class AsyncMock(AsyncMockMixin, AsyncMagicMixin, Mock):
recognized as an async function, and the result of a call is an awaitable:

>>> mock = AsyncMock()
>>> iscoroutinefunction(mock)
>>>inspect.iscoroutinefunction(mock)
True
>>> inspect.isawaitable(mock())
True
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Deprecate :func:`!asyncio.iscoroutinefunction` in favor of
:func:`inspect.iscoroutinefunction`.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp