diff --git a/Lib/inspect.py b/Lib/inspect.py index 8bb3a375735af6..0acc9789441b1d 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -410,12 +410,20 @@ 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 + 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 + #now regular case return _has_code_flag(obj, CO_COROUTINE) or _has_coroutine_mark(obj) def isasyncgenfunction(obj): 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