Skip to content

Conversation

@yihuang
Copy link

@yihuang yihuang commented Mar 24, 2025

Otherwise, it's impossible to create generic stream response for the same endpoint for both sync and async cases.

ref: #156 (comment)

@yihuang yihuang changed the title pass is_async to handler feat: pass is_async to handler to return correct type of stream response Mar 24, 2025
@lundberg
Copy link
Owner

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)
Copy link
Owner

@lundberg lundberg May 21, 2025

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 🤔

Copy link
Author

Choose a reason for hiding this comment

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

sounds good, done.

@yihuang yihuang requested a review from lundberg May 21, 2025 08:24
Co-authored-by: Jonas Lundberg <[email protected]>
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.

2 participants