Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-94912: Added marker for non-standard coroutine function detection#99247
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
4cf8e986b8fa87fa22a16513d358397a975d156eab34859de47a9feacd6c491629dd81a518c0fc6d2b88b7249a83bc72e2c073cf75ffba32File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -358,6 +358,20 @@ attributes: | ||
| wrapped function is a :term:`coroutine function`. | ||
| .. function:: markcoroutinefunction(object) | ||
carltongibson marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| Decorator to mark a callable as a :term:`coroutine function` if it would not | ||
| otherwise be detected by :func:`iscoroutinefunction`. | ||
| This may be of use for sync functions that return an awaitable or objects | ||
| implementing an :keyword:`async def` ``__call__``. | ||
| Prefer :keyword:`async def` functions or calling the function and testing | ||
| the return with :func:`isawaitable` where feasible. | ||
| .. versionadded:: 3.12 | ||
| .. function:: iscoroutine(object) | ||
| Return ``True`` if the object is a :term:`coroutine` created by an | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -202,6 +202,25 @@ def test_iscoroutine(self): | ||
| gen_coroutine_function_example)))) | ||
| self.assertTrue(inspect.isgenerator(gen_coro)) | ||
| # Use subtest initially to see both failures. | ||
| with self.subTest("Wrapper not recognised."): | ||
| # First case: sync function returning an awaitable. | ||
| async def _fn3(): | ||
| pass | ||
| def fn3(): | ||
| return _fn3() | ||
| self.assertTrue(inspect.iscoroutinefunction(fn3)) | ||
| with self.subTest("Awaitable instance not recongnised."): | ||
| # Second case: a class with an async def __call__. | ||
| # - instance is awaitable. | ||
| class Cl: | ||
| async def __call__(self): | ||
| ||
| pass | ||
| cl = Cl() | ||
| self.assertTrue(inspect.iscoroutinefunction(cl)) | ||
| self.assertFalse( | ||
| inspect.iscoroutinefunction(unittest.mock.Mock())) | ||
| self.assertTrue( | ||