aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi/expr.py
diff options
context:
space:
mode:
authorJohn Snow <jsnow@redhat.com>2022-05-02 18:54:20 -0400
committerJohn Snow <jsnow@redhat.com>2025-09-15 14:36:01 -0400
commita50b8572f0e3873db64dd6660cea047f067ca5f7 (patch)
treee0b9cd116e29be5e81507b5274b44636220b8d6d /scripts/qapi/expr.py
parent653f501434889b23a5062b3fe00488d140eb79fd (diff)
downloadqemu-a50b8572f0e3873db64dd6660cea047f067ca5f7.zip
qemu-a50b8572f0e3873db64dd6660cea047f067ca5f7.tar.gz
qemu-a50b8572f0e3873db64dd6660cea047f067ca5f7.tar.bz2
python: backport 'make require() preserve async-ness'
This is not strictly needed functionality-wise, but doing this allows sphinx to see which decorated methods are async. Without this, sphinx misses the "async" classifier on generated docs, which ... for an async library, isn't great. It does make an already gnarly function even gnarlier, though. So, what's going on here? A synchronous function (like require() before this patch) can return a coroutine that can be awaited on, for example: def some_func(): return asyncio.task(asyncio.sleep(5)) async def some_async_func(): await some_func() However, this function is not considered to be an "async" function in the eyes of the abstract syntax tree. Specifically, some_func.__code__.co_flags will not be set with CO_COROUTINE. The interpreter uses this flag to know if it's legal to use "await" from within the body of the function. Since this function is just wrapping another function, it doesn't matter much for the decorator, but sphinx uses the stdlib inspect.iscoroutinefunction() to determine when to add the "async" prefix in generated output. This function uses the presence of CO_COROUTINE. So, in order to preserve the "async" flag for docs, the require() decorator needs to differentiate based on whether it is decorating a sync or async function and use a different wrapping mechanism accordingly. Phew. Signed-off-by: John Snow <jsnow@redhat.com> cherry picked from commit python-qemu-qmp@40aa9699d619849f528032aa456dd061a4afa957 Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'scripts/qapi/expr.py')
0 files changed, 0 insertions, 0 deletions