-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iscoroutinefunction
returns False for wrapper functions with update_wrapper
applied
#100317
Comments
iscoroutinefunction
returns False for wrapped functions with update_wrapper
appliediscoroutinefunction
returns False for wrapper functions with update_wrapper
applied
I agree that the behaviour you describe is what I would also expect. Searching for the phrase "def is coroutine" in the source I found this link:
Which might suggest that your use case is not supported. (I think it ought to be). |
#99247 recently added
But this is a lot of boilerplate. This does raise some questions for
I think we should discard option 1 as breaking the contract of Given that CCing people actively involved in #99247 @carltongibson @kumaraditya303 @gvanrossum |
Is two lines really that much boilerplate? (If you need it enough you can write a helper that does it in one. :-) I worry there's a fundamental problem with automatically passing the "iscoroutinefunction" bit in For this reason I'm not a fan of automatically applying I also note that wrapping an async function in a sync wrapper may not do the right thing. E.g. a wrapper like this typical example:
would print the "result" immediately when a wrapped async function is called, not when it returns. |
Thanks @carljm. I have Django's various decorators in the queue for updating to support async views correctly. I think I'd expect that I'd have to write this version that you have (with the additional lines):
I note that if you define
So then we're in the exact use-case for |
When decorating a
async
function with a decorator that uses@functools.wraps
orupdate_wrapper
inspect.iscoroutinefunction
returns False.The following code demonstrates this issue:
I would expect the last assert statement to pass
The text was updated successfully, but these errors were encountered: