← 返回首页
gh-81371: implementing checking async generator methods by wrongnull · Pull Request #102129 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

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

Provide feedback

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

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

gh-81371: implementing checking async generator methods#102129

Closed
wrongnull wants to merge 3 commits into
python:mainfrom
wrongnull:patch-2
Closed

gh-81371: implementing checking async generator methods#102129
wrongnull wants to merge 3 commits into
python:mainfrom
wrongnull:patch-2

Conversation

wrongnull commented Feb 21, 2023
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

wrongnull changed the title implementing checking async generator methods gh-81371: implementing checking async generator methods Feb 22, 2023
blurb-it Bot and others added 2 commits February 22, 2023 02:14
well, now I'm not sure if this changes matches your excpectations about the way how stdlib should look like

wrongnull commented Feb 22, 2023
edited
Loading

Copy link
Copy Markdown
Contributor Author

Is there one certain way to define if callable returns awaitable? I mean it is possible to reimplement some logic in C. For instance callable can has special flag to this purpose. It's because I'm not sure if my patch handles all possible corner cases so maybe there are more subtle ones. So if the checked object was not declared with async def the only way to check this condition is brute force it manually, I guess.

sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Couple of thoughts:

  1. There are other ways to do that. Flags, coroutine marks, etc. Why this one is the best one? (I am not an asyncio expert)
  2. Is it a problem worth fixing at all?

@@ -0,0 +1 @@
This PR may fix the issue 81371

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

May? Or does it? Please, also specify what the issue is. These are user-facing notes. It must be clear without a github link.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

May? Or does it? Please, also specify what the issue is. These are user-facing notes. It must be clear without a github link.

I'm not 100% sure if it does. In the original issue those methods just returns some awaitable objects that doesn't pass the check. And I fixed it, but only for this certain example (I will add the tests soon). The obstacle is that I don't know if there are similar functions somewhere in the inerpreter. I'm not an internals expert. It would be great if you or someone else could suggest me such places.

Comment thread Lib/inspect.py
Coroutine functions are normally defined with "async def" syntax, but may
be marked via markcoroutinefunction.
"""
#check if obj is async gen method and returns awaitable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Please, at least add tests for this feature.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

as soon as I fully understand the original question

carljm commented Feb 22, 2023

Copy link
Copy Markdown
Member

Is there one certain way to define if callable returns awaitable?

See #81371 (comment)

I don't think the current approach in this PR is the right approach; we shouldn't be checking against an approved list of method names.

carljm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

See above comment.

wrongnull commented Feb 23, 2023
edited
Loading

Copy link
Copy Markdown
Contributor Author

Is there one certain way to define if callable returns awaitable?

See #81371 (comment)

I don't think the current approach in this PR is the right approach; we shouldn't be checking against an approved list of method names.

But there is no way to add attribute to builtin function without monkey patching. Do we need new type(s) to this? Such as builtin_coroutine_function_or_method
Or at least add special flag to already exists ones

Copy link
Copy Markdown
Contributor Author

What if PyCFunctionObject structure contains flags that match co_flags field in code object? Or will they carry the same meaning

Copy link
Copy Markdown
Contributor

This isn't the way to fix this, I am closing this, please continue the discussion on the issue.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

asyncio.iscoroutinefunction(<async_generator>.asend) returns False

5 participants

Footer

© 2026 GitHub, Inc.