-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
builtins.help function is not much help with async functions #80226
Comments
It is very important when using a callable to know whether it is async or not. It is expected that
Note there is no way to tell whether the result of the function needs to be awaited. In the similar case of generator functions versus regular functions, one obvious solution is to add a type annotation. That doesn't work here, since PEP-0484 indicates that the correct annotation for a coroutine function is the type that is awaited, not the coroutine object created when the function is called.
One awkward workaround is to wrap the coroutine function in a regular function:
|
This would be a reasonable addition to help(). Would you like to make a PR? An "async def" can be detected with inspect.iscoroutinefunction(the_answer2). |
Thanks for the suggestion, Raymond. I was toying with the idea of a PR, but wasn’t sure what the resolution should be, and it’s a rather subtle decision for my first contribution. It seems to me that this might be an oversight in PEP-0484, and the purest resolution is that either Generator and Coroutine should both be part of the type signature or neither should be. If the PEP is indeed correct, the help output *could* look like: async the_answer2() -> int Which would be equivalent to the (functionally identical) wrapper: the_answer3() -> Awaitable[int] Philosophically, does asyncness belong on the left or right of the arrow? Should it change just because of how the function is expressed? |
Note to future self: whatever solution should also play nice with functools.partial |
async
for async functions #12010Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: