From a8c74897fdcc7ec695f501d96daa26aadd76fb00 Mon Sep 17 00:00:00 2001 From: Bogdan Romanyuk <65823030+wrongnull@users.noreply.github.com> Date: Tue, 21 Feb 2023 23:53:40 +0300 Subject: [PATCH 1/3] implementing checking async generator methods This PR may fix #81371 --- Lib/inspect.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Lib/inspect.py b/Lib/inspect.py index 8bb3a375735af6..0b60bc7dd16fe1 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -410,12 +410,19 @@ def markcoroutinefunction(func): func._is_coroutine_marker = _is_coroutine_marker return func +_agen_methods = ("__anext__", "aclose", "asend", "athrow") + def iscoroutinefunction(obj): """Return true if the object is a coroutine function. Coroutine functions are normally defined with "async def" syntax, but may be marked via markcoroutinefunction. """ + #check if obj is async gen method and returns awaitable + is_valid = isbuiltin(obj) or ismethodwrapper(obj) + if is_valid and isasyncgen(obj.__self__) and obj.__name__ in _agen_methods: + return True + #now regular case return _has_code_flag(obj, CO_COROUTINE) or _has_coroutine_mark(obj) def isasyncgenfunction(obj): From f309fbdf38b07d16da95e114187a935150d4e69e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 22 Feb 2023 02:14:40 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-02-22-02-14-38.gh-issue-81371.tUo0u1.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-02-22-02-14-38.gh-issue-81371.tUo0u1.rst diff --git a/Misc/NEWS.d/next/Library/2023-02-22-02-14-38.gh-issue-81371.tUo0u1.rst b/Misc/NEWS.d/next/Library/2023-02-22-02-14-38.gh-issue-81371.tUo0u1.rst new file mode 100644 index 00000000000000..b031986179e76c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-02-22-02-14-38.gh-issue-81371.tUo0u1.rst @@ -0,0 +1 @@ +This PR may fix the issue 81371 From d16fa1a630cf95c056c327a3401412b89f079cdb Mon Sep 17 00:00:00 2001 From: Bogdan Romanyuk <65823030+wrongnull@users.noreply.github.com> Date: Wed, 22 Feb 2023 18:42:03 +0300 Subject: [PATCH 3/3] handle one more corner case well, now I'm not sure if this changes matches your excpectations about the way how stdlib should look like --- Lib/inspect.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/inspect.py b/Lib/inspect.py index 0b60bc7dd16fe1..0acc9789441b1d 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -419,6 +419,7 @@ def iscoroutinefunction(obj): be marked via markcoroutinefunction. """ #check if obj is async gen method and returns awaitable + obj = functools._unwrap_partial(obj) is_valid = isbuiltin(obj) or ismethodwrapper(obj) if is_valid and isasyncgen(obj.__self__) and obj.__name__ in _agen_methods: return True