-
Notifications
You must be signed in to change notification settings - Fork 53
feat: pass is_async to handler to return correct type of stream response #296
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
base: master
Are you sure you want to change the base?
Conversation
|
Looks like a usable feature, will take a look, thanks |
respx/models.py
Outdated
| try: | ||
| # Call side effect | ||
| result: RouteResultTypes = effect(request, **kwargs) | ||
| result: RouteResultTypes = effect(request, is_async, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be fully backwards compatible, and not force users to change their existing side effects, I think we could be graceful here and only pass is_async among kwargs if the implemented side effect specs it, i.e. like the route kwarg is handled above.
e.g.
if "is_async" in argspec.args:
kwargs["is_async"] = is_async.. maybe handle both spec'ed as arg or kwarg 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good, done.
Co-authored-by: Jonas Lundberg <[email protected]>
Otherwise, it's impossible to create generic stream response for the same endpoint for both sync and async cases.
ref: #156 (comment)