mirakour opened a new pull request, #845: URL: https://github.com/apache/burr/pull/845
Closes #607 ## What and Why The `stream_type` parameter in `@streaming_action.pydantic` and `pydantic_streaming_action` currently only accepts a single Pydantic model class or `dict`. Passing a union type (e.g. `ModelA | ModelB` using Python 3.10+ syntax) raises a `TypeError` because `types.UnionType` is not included in the `PartialType` alias. This PR fixes that by expanding `PartialType` to include `types.UnionType` on Python 3.10+ using a version guard, and updating the `stream_type` annotation in `action.py` accordingly. ## Changes - `burr/integrations/pydantic.py`: Added `import sys` and a version guard so `PartialType` includes `types.UnionType` on Python 3.10+ - `burr/core/action.py`: Updated the `stream_type` annotation in `streaming_action.pydantic()` from `Union[Type["BaseModel"], Type[dict]]` to `Union[Type["BaseModel"], Type[dict], Any]` - `tests/integrations/test_burr_pydantic.py`: Added 3 regression tests guarded with `@pytest.mark.skipif(sys.version_info < (3, 10), ...)` ## How I tested this Added 3 regression tests in `tests/integrations/test_burr_pydantic.py`: 1. `test_validate_streaming_signature_accepts_union_stream_type` — verifies the internal validation function accepts `types.UnionType` 2. `test_pydantic_streaming_action_accepts_union_stream_type` — verifies `@pydantic_streaming_action` works with `stream_type=ModelA | ModelB` 3. `test_streaming_action_pydantic_decorator_accepts_union_stream_type` — same for the `@streaming_action.pydantic` decorator All tests are skipped automatically on Python < 3.10. ## Notes - No behavior change on Python < 3.10; the original `PartialType` is preserved for older versions - The `Any` annotation in `action.py` is intentionally broad to accommodate future union-like types without requiring another version guard ## Checklist - [x] PR has an informative and human-readable title (this will be pulled into the release notes) - [x] Changes are limited to a single goal (no scope creep) - [x] Code passed the pre-commit check & code is left cleaner/nicer than when first encountered. - [x] Any _change_ in functionality is tested - [ ] New functions are documented (with a description, list of inputs, and expected output) - [x] Placeholder code is flagged / future TODOs are captured in comments - [x] Project documentation has been updated if adding/changing functionality. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
