From dac39e8c5f38fd5a8283dc248f1c4735dc587420 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Sun, 22 Mar 2026 12:33:45 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20mypy=20[type-arg]=20error?= =?UTF-8?q?=20by=20giving=20Data=20TypeVar=20a=20default=20of=20Any?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- fastapi/sse.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fastapi/sse.py b/fastapi/sse.py index 9846b27061..dc204cf0d9 100644 --- a/fastapi/sse.py +++ b/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