pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/pull/148708

f="https://github.githubassets.com/assets/actions-0e714a98ea09295a.css" /> Refactor WSGIEnvironment to use TypedDict by bangseongbeom · Pull Request #148708 · python/cpython · GitHub
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
Copy link
Copy Markdown
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

I am not fond of adding typing in the stdlib. This should be done in typeshed.

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Apr 19, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@picnixz
Copy link
Copy Markdown
Member

picnixz commented Apr 19, 2026

Oh my bad they are actually added in types.py. Ok this seems fine to me. However please use the issue that was used to add those types and please create a NEWS entry.

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.

3 participants

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy