Refactor WSGIEnvironment to use TypedDict#148708
Open
bangseongbeom wants to merge 1 commit intopython:mainfrom
Open
Refactor WSGIEnvironment to use TypedDict#148708bangseongbeom wants to merge 1 commit intopython:mainfrom
bangseongbeom wants to merge 1 commit intopython:mainfrom
Conversation
There was a problem hiding this comment.
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 aTypedDictdefinition listing common WSGI/CGI keys. - Add typing imports needed for the new
TypedDictshape (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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andwsgi.run_onceare typed asAnybecause they are only specified as being evaluable as true or false, not explicitly asbool. In addition, since according to the PEPenvironis valid with arbitrary extra items, soextra_items=Anyis 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 beNotRequired[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.