From 6b18cd11ca6c38e2e43fbb71450ec5bdc6b321b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=A9=EC=84=B1=EB=B2=94=20=28Bang=20Seongbeom=29?= Date: Sat, 18 Apr 2026 02:06:41 +0900 Subject: [PATCH] Refactor WSGIEnvironment to use TypedDict --- Lib/wsgiref/types.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Lib/wsgiref/types.py b/Lib/wsgiref/types.py index ef0aead5b28b64..67894da933d49c 100644 --- a/Lib/wsgiref/types.py +++ b/Lib/wsgiref/types.py @@ -2,7 +2,7 @@ from collections.abc import Callable, Iterable, Iterator from types import TracebackType -from typing import Any, Protocol, TypeAlias +from typing import Any, Literal, NotRequired, Protocol, TypeAlias, TypedDict __all__ = [ "StartResponse", @@ -26,7 +26,29 @@ def __call__( /, ) -> Callable[[bytes], object]: ... -WSGIEnvironment: TypeAlias = dict[str, Any] +WSGIEnvironment = TypedDict( + "WSGIEnvironment", + { + "REQUEST_METHOD": str, + "SCRIPT_NAME": NotRequired[str], + "PATH_INFO": NotRequired[str], + "QUERY_STRING": NotRequired[str], + "CONTENT_TYPE": NotRequired[str], + "CONTENT_LENGTH": NotRequired[str], + "SERVER_NAME": str, + "SERVER_PORT": str, + "SERVER_PROTOCOL": str, + "wsgi.version": tuple[Literal[1], Literal[0]], + "wsgi.url_scheme": str, + "wsgi.input": "InputStream", + "wsgi.errors": "ErrorStream", + "wsgi.multithread": Any, + "wsgi.multiprocess": Any, + "wsgi.run_once": Any, + "wsgi.file_wrapper": NotRequired["FileWrapper"], + }, + extra_items=Any, +) WSGIApplication: TypeAlias = Callable[[WSGIEnvironment, StartResponse], Iterable[bytes]]