Browse Source

🐛 Fix mypy [type-arg] error by giving Data TypeVar a default of Any

Bare `ServerSentEvent` (without a type parameter) now silently resolves
to `ServerSentEvent[Any]`, so existing code and the `_check_data_exclusive`
return annotation require no changes and pass mypy without `[type-arg]`
errors.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
pull/15191/head
Ben Mosher 3 months ago
parent
commit
dac39e8c5f
  1. 6
      fastapi/sse.py

6
fastapi/sse.py

@ -1,10 +1,12 @@
from typing import Annotated, Any, Generic, TypeVar
from typing import Annotated, Any, Generic
from typing_extensions import TypeVar
from annotated_doc import Doc
from pydantic import AfterValidator, BaseModel, ConfigDict, Field, model_validator
from starlette.responses import StreamingResponse
Data = TypeVar("Data")
Data = TypeVar("Data", default=Any)
"""Type variable for the `data` payload of a `ServerSentEvent`.
Use ``ServerSentEvent[MyModel]`` to indicate that every event in the

Loading…
Cancel
Save