Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep an async function marker when @pass_ is used #79

Merged
merged 1 commit into from
Nov 27, 2023

Conversation

ikalnytskyi
Copy link
Owner

Unfortunately, when the @picobox.pass_() decorator is used, a wrapped coroutine function (i.e. an async function) loses its a coroutine function marker, i.e. inspect.iscoroutinefunction() returns False for such function.

Turns out that there are a lot of software out there that support both sync and async interfaces, and may choose one based on the type of a passed function. For instance, Starlette, a web-framework, checks a provided route function for being a coroutine function before choosing how to execute in (i.e. in an event loop or in a thread pool).

This patch fixes @picobox.pass_() to return a coroutine function when a wrapped function is also a coroutine function.

Fixes #78

Unfortunately, when the `@picobox.pass_()` decorator is used, a wrapped
coroutine function (i.e. an async function) loses its a coroutine
function marker, i.e. `inspect.iscoroutinefunction()` returns `False`
for such function.

Turns out that there are a lot of software out there that support both
sync and async interfaces, and may choose one based on the type of a
passed function. For instance, Starlette, a web-framework, checks a
provided route function for being a coroutine function before choosing
how to execute in (i.e. in an event loop or in a thread pool).

This patch fixes `@picobox.pass_()` to return a coroutine function when
a wrapped function is also a coroutine function.

Fixes #78
@ikalnytskyi ikalnytskyi merged commit c1c6725 into master Nov 27, 2023
14 checks passed
@ikalnytskyi ikalnytskyi deleted the bug/pass-with-coroutines branch November 27, 2023 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add coroutine functions support to pass_ decorator
1 participant