GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-86178: Add wsgiref.types by srittau · Pull Request #32335 · python/cpython

Conversation

@srittau

@srittau srittau commented Apr 5, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

https://bugs.python.org/issue42012

#86178

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@srittau
Add wsgiref.types
b409b9e
@bedevere-bot bedevere-bot added the awaiting review label Apr 5, 2022
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Apr 5, 2022
@JelleZijlstra
JelleZijlstra self-requested a review April 5, 2022 15:54
@AlexWaygood

AlexWaygood commented Apr 5, 2022

Copy link
Copy Markdown
Member

My first thought when I saw this was, "How will we ensure that these types remain up to date with the rest of the wsgiref module?" But these types do appear to have been very stable in typeshed. So, perhaps it's not much of an issue.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood AlexWaygood added the type-feature A feature request or enhancement label Apr 5, 2022
@srittau

srittau commented Apr 5, 2022

Copy link
Copy Markdown
Contributor Author

These types are just a representation of PEP 3333, not of the specifics of wsgiref. The only improvement I can see at the moment is potentially typing WSGIEnvironment using TypedDict for some of the predefined fields.

AlexWaygood and bangseongbeom reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra
JelleZijlstra reviewed Apr 6, 2022
View reviewed changes
Comment thread Lib/wsgiref/types.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/wsgiref/types.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/wsgiref.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/wsgiref.rst
:synopsis: WSGI types for static type checking


This module provides various types for static type checking as described

@JelleZijlstra JelleZijlstra Apr 6, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This documentation feels a bit thin. Perhaps we could have examples of WSGI code using some of these aliases.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@srittau srittau Apr 6, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I agree about the examples, but when I procrastinated over two options, I gave up :)

  1. Add an example to this section. But right below this section there is the "Example" section and this would feel like a duplication.
  2. Add types to the example section. But in a way this distracts from the point of the example.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Lib/wsgiref/types.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood
AlexWaygood reviewed Apr 6, 2022
View reviewed changes
Comment thread Lib/wsgiref/types.py
@@ -0,0 +1,53 @@
"""WSGI-related types for static type checking"""

@AlexWaygood AlexWaygood Apr 6, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It might be good to add a note to the module docstring that any changes contributors want to make to this file will need to be made to typeshed simultaneously if they're to have any meaning to static type checkers

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@srittau srittau Apr 6, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'm not sure we should mention typeshed explicitly for a few reasons:

  • I don't want to burden CPython contributors to need to contribute to typeshed.
  • In typeshed we are pretty good in picking up changes, and for CPython we have quite some time to make these changes.
  • While this is currently not the case, type checkers could in theory use the implementation module to type check instead of typeshed. In fact, I have an idea to optionally direct type checkers to the stdlib in cases like this, so it's possible that this comment would get outdated during the life time of Python 3.11.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
srittau added 2 commits April 6, 2022 10:23
@srittau
Mark all arguments as positional-only
0f43b14
@srittau
Extend type documentation
645bd8d
@srittau
srittau requested a review from JelleZijlstra April 11, 2022 19:24
JelleZijlstra
JelleZijlstra approved these changes Apr 12, 2022
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels Apr 12, 2022
@JelleZijlstra JelleZijlstra self-assigned this Apr 12, 2022
@AlexWaygood AlexWaygood added the topic-typing label Apr 13, 2022
@AlexWaygood AlexWaygood mentioned this pull request Apr 14, 2022
Add typing to 3.11 What's New #91491
Closed
@srittau srittau closed this Apr 14, 2022
@srittau srittau reopened this Apr 14, 2022
@srittau srittau changed the title bpo-42012: Add wsgiref.types gh-86178: Add wsgiref.types Apr 14, 2022
@JelleZijlstra

JelleZijlstra commented Apr 14, 2022

Copy link
Copy Markdown
Member

I'll merge this in a few days unless more feedback comes up.

AlexWaygood reacted with thumbs up emoji srittau and sirosen reacted with hooray emoji
All reactions
  • 👍 1 reaction
  • 🎉 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sirosen sirosen mentioned this pull request Apr 15, 2022
What is the "right way" to annotate a wsgi application with middlewares? python/typeshed#7585
Closed
Akuli
Akuli reviewed Apr 15, 2022
View reviewed changes
Comment thread Lib/wsgiref/types.py Outdated
class ErrorStream(Protocol):
"""WSGI error stream as defined in PEP 3333"""
def flush(self) -> None: ...
def write(self, s: str, /) -> None: ...

@Akuli Akuli Apr 15, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This should probably be -> object. File objects typically return the number of bytes written as int.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@JelleZijlstra JelleZijlstra Apr 15, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Same for flush, although that doesn't typically return anything.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@srittau srittau Apr 15, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is a bit embarrassing. :) Will fix.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@srittau
Use object instead of None as protocol return type
fed8b31
@JelleZijlstra
JelleZijlstra merged commit 0ddc63b into python:main Apr 16, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Apr 16, 2022
@srittau
srittau deleted the wsgiref-types branch April 16, 2022 18:01
@srittau srittau mannequin mentioned this pull request Apr 20, 2022
typing support in wsgiref #86178
Closed
@DMRobertson DMRobertson mentioned this pull request Feb 7, 2023
Typecheck tests.rest.media.v1.test_media_storage matrix-org/synapse#15008
Merged
@bangseongbeom bangseongbeom mentioned this pull request Apr 18, 2026
gh-86178: Refactor WSGIEnvironment to use TypedDict #148708
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JelleZijlstra JelleZijlstra JelleZijlstra approved these changes
@AlexWaygood AlexWaygood AlexWaygood left review comments
+1 more reviewer
@Akuli Akuli Akuli left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@JelleZijlstra JelleZijlstra

Labels

topic-typing type-feature A feature request or enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@srittau @AlexWaygood @JelleZijlstra @Akuli @the-knights-who-say-ni @bedevere-bot
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.