Skip to content

gh-94912: Added marker for non-standard coroutine function detection#99247

Merged
gvanrossum merged 16 commits intopython:mainfrom
carltongibson:fix-issue-XXXXX
Dec 18, 2022
Merged

gh-94912: Added marker for non-standard coroutine function detection#99247
gvanrossum merged 16 commits intopython:mainfrom
carltongibson:fix-issue-XXXXX

Conversation

@carltongibson
Copy link
Copy Markdown
Contributor

@carltongibson carltongibson commented Nov 8, 2022

This is ref the discussion on #94912 to add an official way of marking callables as coroutine functions where they would not otherwise be detected.

cc. @gvanrossum @andrewgodwin I've just had time this afternoon to block off some first tests, and docs. I wanted to break ground so we keep it moving. It's very consciously drafts: please make suggestions of how you think it should go.

@gvanrossum Can I ask for a pointer on how I'm meant to set co_flags for the _has_code_flag() check? 🤔

cpython/Lib/inspect.py

Lines 376 to 385 in c43714f

def _has_code_flag(f, flag):
"""Return true if ``f`` is a function (or a method or functools.partial
wrapper wrapping a function) whose code object has the given ``flag``
set in its flags."""
while ismethod(f):
f = f.__func__
f = functools._unwrap_partial(f)
if not (isfunction(f) or _signature_is_functionlike(f)):
return False
return bool(f.__code__.co_flags & flag)

Thanks!

First PR on CPython, so likely it's wrong 😊

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Tests in the Lib/test dir topic-asyncio

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants