Skip to content

Commit 6b18cd1

Browse files
committed
Refactor WSGIEnvironment to use TypedDict
1 parent 2faceee commit 6b18cd1

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

Lib/wsgiref/types.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from collections.abc import Callable, Iterable, Iterator
44
from types import TracebackType
5-
from typing import Any, Protocol, TypeAlias
5+
from typing import Any, Literal, NotRequired, Protocol, TypeAlias, TypedDict
66

77
__all__ = [
88
"StartResponse",
@@ -26,7 +26,29 @@ def __call__(
2626
/,
2727
) -> Callable[[bytes], object]: ...
2828

29-
WSGIEnvironment: TypeAlias = dict[str, Any]
29+
WSGIEnvironment = TypedDict(
30+
"WSGIEnvironment",
31+
{
32+
"REQUEST_METHOD": str,
33+
"SCRIPT_NAME": NotRequired[str],
34+
"PATH_INFO": NotRequired[str],
35+
"QUERY_STRING": NotRequired[str],
36+
"CONTENT_TYPE": NotRequired[str],
37+
"CONTENT_LENGTH": NotRequired[str],
38+
"SERVER_NAME": str,
39+
"SERVER_PORT": str,
40+
"SERVER_PROTOCOL": str,
41+
"wsgi.version": tuple[Literal[1], Literal[0]],
42+
"wsgi.url_scheme": str,
43+
"wsgi.input": "InputStream",
44+
"wsgi.errors": "ErrorStream",
45+
"wsgi.multithread": Any,
46+
"wsgi.multiprocess": Any,
47+
"wsgi.run_once": Any,
48+
"wsgi.file_wrapper": NotRequired["FileWrapper"],
49+
},
50+
extra_items=Any,
51+
)
3052
WSGIApplication: TypeAlias = Callable[[WSGIEnvironment, StartResponse],
3153
Iterable[bytes]]
3254

0 commit comments

Comments
 (0)