-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-86178: Add wsgiref.types #32335
gh-86178: Add wsgiref.types #32335
Conversation
My first thought when I saw this was, "How will we ensure that these types remain up to date with the rest of the |
These types are just a representation of PEP 3333, not of the specifics of |
:synopsis: WSGI types for static type checking | ||
|
||
|
||
This module provides various types for static type checking as described |
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.
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 :)
- Add an example to this section. But right below this section there is the "Example" section and this would feel like a duplication.
- Add types to the example section. But in a way this distracts from the point of the example.
@@ -0,0 +1,53 @@ | |||
"""WSGI-related types for static type checking""" |
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
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.
I'll merge this in a few days unless more feedback comes up. |
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: ... |
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
.
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.
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.
https://bugs.python.org/issue42012
#86178