eeshsaxena commented on PR #845:
URL: https://github.com/apache/burr/pull/845#issuecomment-5058510149
Heads up that #813 (opened 2026-06-20) implements the same feature, touching
the same two files. Worth the maintainers deciding between them rather than
reviewing both in isolation.
Having read both, there are two cases this one may not cover.
`requires-python` is `>=3.9`, so both matter:
**1. `typing.Union[A, B]` on Python 3.10-3.13.** The check here keys on
`types.UnionType`, which only covers the PEP 604 `A | B` form. On 3.10-3.13
`typing.Union[A, B]` is a `typing._UnionGenericAlias` and is not an instance of
`types.UnionType`, so it would still be rejected. Python 3.14 unified the two
(I confirmed `isinstance(Union[int, str], types.UnionType)` is `True` there,
and `type(int | str) is type(Union[int, str])`), but on the older supported
versions they are distinct. The issue example uses `|`, though `Union[...]`
seems worth accepting too since the existing annotation is written that way.
**2. Union members are not validated.** Widening `PartialType` means `int |
str` is accepted as a `stream_type` even though neither member is a BaseModel
or dict.
#813 handles both by keeping the annotation wide and doing the real check at
decoration time:
```python
if typing.get_origin(t) is Union: # typing.Union[...]
return all(_is_valid_stream_type(arg) for arg in typing.get_args(t))
_UnionType = getattr(types, "UnionType", None) # X | Y, guarded for
3.9
if _UnionType is not None and isinstance(t, _UnionType):
return all(_is_valid_stream_type(arg) for arg in t.__args__)
```
That also speaks to @elijahbenizzy's question on #607 ("does it actually
detect per-instance rather than assume they're all the same?"): recursing into
the members is what makes an invalid union fail at decoration time rather than
surfacing later during streaming.
Not trying to talk down your PR - the smaller diff is appealing and the
version guard is careful. But if the two get merged into one, the member
validation and the `typing.Union` path look worth carrying over.
--
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]