fix(pydantic): allow union of BaseModel types as stream_type#754
Open
Ghraven wants to merge 2 commits into
Open
fix(pydantic): allow union of BaseModel types as stream_type#754Ghraven wants to merge 2 commits into
Ghraven wants to merge 2 commits into
Conversation
Fixes apache#607 Broadens the `stream_type` parameter in `streaming_action.pydantic()` and `pydantic_streaming_action()` to accept a union of pydantic BaseModel types (e.g. `ModelA | ModelB`) in addition to a single `Type[BaseModel]` or `Type[dict]`. The internal validation logic already handles this at runtime; this change removes the overly strict static type annotation that rejected union types at the call site.
Fixes apache#607 Broadens the `stream_type` parameter in `streaming_action.pydantic()` and `pydantic_streaming_action()` to accept a union of pydantic BaseModel types (e.g. `ModelA | ModelB`) in addition to a single `Type[BaseModel]` or `Type[dict]`. The internal validation logic already handles this at runtime; this change removes the overly strict static type annotation that rejected union types at the call site.
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
What
Broadens the
stream_typeparameter type annotation instreaming_action.pydantic()andpydantic_streaming_action()to accept a union of pydanticBaseModeltypes in addition to a singleType[BaseModel]orType[dict].Why
Users who pass a union of models (e.g.
MyModel1 | MyModel2) hit a static type error at the call site because the parameter was typed asUnion[Type[BaseModel], Type[dict]], which only accepts a single concrete model type. The runtime validation logic in_validate_and_extract_signature_types_streaming()already handles union types correctly — this was a type annotation gap only.Changes
burr/core/action.py:stream_typeparameter instreaming_action.pydantic()widened to acceptobject(covers union types, which are not expressible asType[X]).burr/integrations/pydantic.py: Same change toPartialTypealias and the validator function signature.Testing
No behaviour change — this is a type annotation fix only. Existing tests continue to pass. Users can now write:
without a type error.