...will convert anything to a str, and I simply arranged for my event objects to return JSON serialization for str.
Furthermore, the data property of ServerSentEvent can be Optional[Any].
It seems to me that since any object will be turned into a string, having Content also include Any would be convenient. Then you could send a stream of any object that's got a good string conversion, and it would work.
I'm making my streams strongly typed in my program, for instance:
(
StreamingEvent
is a union of Pydantic base models.)But mypy complains about the
content
argument toEventSourceResponse
.The code still works, because
ensure_bytes
athttps://github.com/sysid/sse-starlette/blob/4b1ec63da5a7da0a0243b699f4d83f04f255a41c/sse_starlette/sse.py#L143
...will convert anything to a
str
, and I simply arranged for my event objects to return JSON serialization forstr
.Furthermore, the
data
property ofServerSentEvent
can beOptional[Any]
.It seems to me that since any object will be turned into a string, having
Content
also includeAny
would be convenient. Then you could send a stream of any object that's got a good string conversion, and it would work.https://github.com/sysid/sse-starlette/blob/4b1ec63da5a7da0a0243b699f4d83f04f255a41c/sse_starlette/sse.py#L146