Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
gvanrossum merged 16 commits intopython:mainfromcarltongibson:fix-issue-XXXXX
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
16 commits
Select commitHold shift + click to select a range
4cf8e98
Added initial test and docs drafts.
carltongibsonNov 8, 2022
6b8fa87
Make first case pass setting code flags.
carltongibsonNov 15, 2022
fa22a16
Adjust iscoroutinefunction() to look for async __call__.
carltongibsonNov 15, 2022
513d358
📜🤖 Added by blurb_it.
blurb-it[bot]Nov 17, 2022
397a975
Moved to decorator; extra tests.
carltongibsonNov 17, 2022
d156eab
Added tests for lambda, @classmethod, and @staticmethod cases.
carltongibsonNov 23, 2022
34859de
Adjusted docs signature for review comment.
carltongibsonNov 23, 2022
47a9fea
Improve grammar in NEWS file
gvanrossumNov 23, 2022
cd6c491
Adjusted docs.
carltongibsonNov 29, 2022
629dd81
Updated for review comments.
carltongibsonNov 30, 2022
a518c0f
Merge branch 'main' into fix-issue-XXXXX
gvanrossumNov 30, 2022
c6d2b88
Use marker for implementation.
carltongibsonDec 6, 2022
b7249a8
Added "What's New..." entry.
carltongibsonDec 6, 2022
3bc72e2
Adjusted implementation.
carltongibsonDec 8, 2022
c073cf7
Renamed to _is_coroutine_marker.
carltongibsonDec 13, 2022
5ffba32
Adjusted implementation and docs.
carltongibsonDec 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Added initial test and docs drafts.
  • Loading branch information
@carltongibson
carltongibson committedNov 17, 2022
commit4cf8e98175e501c671c3c43016d3df443def9ffc
14 changes: 14 additions & 0 deletionsDoc/library/inspect.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -358,6 +358,20 @@ attributes:
wrapped function is a :term:`coroutine function`.


.. function:: markcoroutinefunction(object)

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
Expand Down
19 changes: 19 additions & 0 deletionsLib/test/test_inspect.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

In the future don't forget to test objects with.__func__ set, because of how_has_code_flag works :)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I haven't followed exactly what you mean here. Sorry. 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Oh, sorry. I've meant that objects likestaticmethod andclassmethod have__func__ property set, where the original function is stored.inspect generally supports this pattern and it should be tested in this case as well :)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@sobolevn — OK, let me have a play and see. Thanks!

pass
cl = Cl()
self.assertTrue(inspect.iscoroutinefunction(cl))

self.assertFalse(
inspect.iscoroutinefunction(unittest.mock.Mock()))
self.assertTrue(
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp