Skip to content

Conversation

@NatureGeorge
Copy link
Contributor

#263 did not fully solve #224.

current behavior

python -m pip install git+https://github.com/jd/tenacity.git@be9bccbb731d28ab0bcd8a4ee5acae70988bf593
from inspect import iscoroutinefunction as inspect_iscoroutinefunction
from asyncio import iscoroutinefunction as asyncio_iscoroutinefunction

from tenacity import retry


async def a():
    pass

print(inspect_iscoroutinefunction(a), asyncio_iscoroutinefunction(a))

b = retry(a)

print(inspect_iscoroutinefunction(b), asyncio_iscoroutinefunction(b))
True True
False True

How to solve

fn._is_coroutine = asyncio.coroutines._is_coroutine

The reason that it passes asyncio.iscoroutinefunction is:

https://docs.python.org/3/library/asyncio-task.html#asyncio.iscoroutinefunction

asyncio.iscoroutinefunction(func)
Return True if func is a coroutine function.
This method is different from inspect.iscoroutinefunction() because it returns True for generator-based coroutine functions decorated with @coroutine.

But it can not pass inspect.iscoroutinefunction since the returned fn is not an async def function.

Through explicitly defining an async function (wrapper) in

def wraps(self, fn):

one can make it pass both inspect.iscoroutinefunction and asyncio.iscoroutinefunction.

jd
jd previously requested changes Dec 14, 2020
@mergify mergify bot dismissed jd’s stale review December 14, 2020 17:17

Pull request has been modified.

@mergify mergify bot merged commit db0f958 into jd:master Dec 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants