implement union type support for streaming actions#813
Conversation
|
Thanks for picking this up and for writing out the investigation so clearly. One small thought from my earlier pass on this issue: adding object to the union does make the type checker accept union values, but it also effectively widens stream_type to almost any value. That may still be the pragmatic choice here, but maintainers may prefer either a more explicit alias/comment around why the parameter is intentionally broad, or a small runtime/type-helper path that recognizes union forms while keeping the public intent narrow. The focused tests for both yping.Union[...] and ModelA | ModelB look useful. Thanks again for moving this forward. |
|
Thank you for your suggestions. That's a good catch. I addressed the issues that you mentioned above. |
|
Thank you for following up and tightening that path. I appreciate you taking the suggestion constructively, and the updated direction looks much clearer to me. Nice work. |
Summary
Extends the
@streaming_action.pydantic()decorator to accept union types likeModel1 | Model2orUnion[Model1, Model2]) for thestream_typeparameter. Previously, only single BaseModel types ordictwere accepted, limiting flexibility for streaming actions that yield multiple result types.Changes
How I tested this
Unit Tests: Created comprehensive test suite with 10 tests that all pass
Notes
Resolved: #607
Checklist