Skip to content

Refactor WSGIEnvironment to use TypedDict#148708

Open
bangseongbeom wants to merge 1 commit intopython:mainfrom
bangseongbeom:wsgi-environment-typed-dict
Open

Refactor WSGIEnvironment to use TypedDict#148708
bangseongbeom wants to merge 1 commit intopython:mainfrom
bangseongbeom:wsgi-environment-typed-dict

Conversation

@bangseongbeom
Copy link
Copy Markdown
Contributor

@bangseongbeom bangseongbeom commented Apr 18, 2026

As mentioned in #32335 (comment), this PR makes WSGIEnvironment use TypedDict. It has items for the CGI variables and WSGI variables specified in PEP 3333. wsgi.multithread, wsgi.multiprocess, and wsgi.run_once are typed as Any because they are only specified as being evaluable as true or false, not explicitly as bool. In addition, since according to the PEP environ is valid with arbitrary extra items, so extra_items=Any is set.

According to PEP 3333, a server or gateway should provide as many CGI variables as possible. This includes variables beginning with HTTP_*, other variables specified in RFC 3875, and mod_ssl variables. If these were to be included in WSGIEnvironment, they would all need to be NotRequired[str], as described in the PEP. Including them could provide some help with IDE/editor autocompletion and inferring types, but there are too many of them, and it is unclear how much to include, so I have not added them for now.

Copilot AI review requested due to automatic review settings April 18, 2026 01:57
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors wsgiref.types.WSGIEnvironment from a plain dict[str, Any] alias into a TypedDict that enumerates key CGI/WSGI environ variables (per PEP 3333), while still permitting arbitrary extra keys via extra_items.

Changes:

  • Replace WSGIEnvironment: TypeAlias = dict[str, Any] with a TypedDict definition listing common WSGI/CGI keys.
  • Add typing imports needed for the new TypedDict shape (TypedDict, NotRequired, Literal).
  • Allow additional environment keys by setting extra_items=Any.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Lib/wsgiref/types.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants