fix: support Union types for stream_type parameter#672
Closed
leobin001 wants to merge 1 commit intoapache:mainfrom
Closed
fix: support Union types for stream_type parameter#672leobin001 wants to merge 1 commit intoapache:mainfrom
leobin001 wants to merge 1 commit intoapache:mainfrom
Conversation
Fixes #607 Allow stream_type to accept Union types like MyModel1 | MyModel2. Changed type hints from Union[Type[BaseModel], Type[dict]] to Any to support Union combinations of BaseModel types. Changes: - Updated PartialType in burr/integrations/pydantic.py to typing.Any - Updated stream_type parameter in streaming_action.pydantic() to Any - Updated _validate_and_extract_signature_types_streaming() signature
Author
|
Closing this PR as I discovered #612 was submitted earlier (Dec 30, 2025) with a better solution that includes proper type hints and test cases. I apologize for the duplicate - I should have checked more carefully for existing PRs before starting work. Thanks to @majiayu000 for the comprehensive fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #607
Summary
This PR allows
stream_typeparameter in@streaming_action.pydanticto accept Union types likeMyModel1 | MyModel2.Problem
Previously, the type hint was:
This caused type checkers to complain when users tried to pass Union types like:
Solution
Changed the type hints to
typing.Anyto support Union combinations of BaseModel types while maintaining backward compatibility.Changes
PartialTypeinburr/integrations/pydantic.pytotyping.Anystream_typeparameter instreaming_action.pydantic()toAny_validate_and_extract_signature_types_streaming()signatureTesting
The change is backward compatible - all existing code using
Type[BaseModel]orType[dict]will continue to work, and now Union types are also supported.