Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.2k
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
16 commits Select commitHold shift + click to select a range
4cf8e98
Added initial test and docs drafts.
carltongibson6b8fa87
Make first case pass setting code flags.
carltongibsonfa22a16
Adjust iscoroutinefunction() to look for async __call__.
carltongibson513d358
📜🤖 Added by blurb_it.
blurb-it[bot]397a975
Moved to decorator; extra tests.
carltongibsond156eab
Added tests for lambda, @classmethod, and @staticmethod cases.
carltongibson34859de
Adjusted docs signature for review comment.
carltongibson47a9fea
Improve grammar in NEWS file
gvanrossumcd6c491
Adjusted docs.
carltongibson629dd81
Updated for review comments.
carltongibsona518c0f
Merge branch 'main' into fix-issue-XXXXX
gvanrossumc6d2b88
Use marker for implementation.
carltongibsonb7249a8
Added "What's New..." entry.
carltongibson3bc72e2
Adjusted implementation.
carltongibsonc073cf7
Renamed to _is_coroutine_marker.
carltongibson5ffba32
Adjusted implementation and docs.
carltongibsonFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
25 changes: 23 additions & 2 deletionsDoc/library/inspect.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletionsDoc/whatsnew/3.12.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
26 changes: 24 additions & 2 deletionsLib/inspect.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletionsLib/test/test_inspect.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -202,6 +202,51 @@ def test_iscoroutine(self): | ||
gen_coroutine_function_example)))) | ||
self.assertTrue(inspect.isgenerator(gen_coro)) | ||
async def _fn3(): | ||
pass | ||
@inspect.markcoroutinefunction | ||
carltongibson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
def fn3(): | ||
return _fn3() | ||
self.assertTrue(inspect.iscoroutinefunction(fn3)) | ||
self.assertTrue( | ||
inspect.iscoroutinefunction( | ||
inspect.markcoroutinefunction(lambda: _fn3()) | ||
) | ||
) | ||
class Cl: | ||
async def __call__(self): | ||
pass | ||
self.assertFalse(inspect.iscoroutinefunction(Cl)) | ||
# instances with async def __call__ are NOT recognised. | ||
self.assertFalse(inspect.iscoroutinefunction(Cl())) | ||
class Cl2: | ||
@inspect.markcoroutinefunction | ||
def __call__(self): | ||
pass | ||
self.assertFalse(inspect.iscoroutinefunction(Cl2)) | ||
# instances with marked __call__ are NOT recognised. | ||
self.assertFalse(inspect.iscoroutinefunction(Cl2())) | ||
class Cl3: | ||
@inspect.markcoroutinefunction | ||
@classmethod | ||
def do_something_classy(cls): | ||
pass | ||
@inspect.markcoroutinefunction | ||
@staticmethod | ||
def do_something_static(): | ||
pass | ||
self.assertTrue(inspect.iscoroutinefunction(Cl3.do_something_classy)) | ||
self.assertTrue(inspect.iscoroutinefunction(Cl3.do_something_static)) | ||
self.assertFalse( | ||
inspect.iscoroutinefunction(unittest.mock.Mock())) | ||
self.assertTrue( | ||
2 changes: 2 additions & 0 deletionsMisc/NEWS.d/next/Library/2022-11-17-10-02-18.gh-issue-94912.G2aa-E.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add :func:`inspect.markcoroutinefunction` decorator which manually marks | ||
a function as a coroutine for the benefit of :func:`iscoroutinefunction`. |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.