Skip to content

fix: support Union types for stream_type parameter#672

Closed
leobin001 wants to merge 1 commit intoapache:mainfrom
leobin001:fix-stream-type-union-support
Closed

fix: support Union types for stream_type parameter#672
leobin001 wants to merge 1 commit intoapache:mainfrom
leobin001:fix-stream-type-union-support

Conversation

@leobin001
Copy link
Copy Markdown

Fixes #607

Summary

This PR allows stream_type parameter in @streaming_action.pydantic to accept Union types like MyModel1 | MyModel2.

Problem

Previously, the type hint was:

stream_type: Union[Type[BaseModel], Type[dict]]

This caused type checkers to complain when users tried to pass Union types like:

union = MyModel1 | MyModel2

@streaming_action.pydantic(
    ...
    stream_type=union,  # Type error!
)

Solution

Changed the type hints to typing.Any to support Union combinations of BaseModel types while maintaining backward compatibility.

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

Testing

The change is backward compatible - all existing code using Type[BaseModel] or Type[dict] will continue to work, and now Union types are also supported.

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
@leobin001
Copy link
Copy Markdown
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!

@leobin001 leobin001 closed this Mar 11, 2026
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.

Streaming Event type, type hint, should support union type

1 participant