@@ -23,6 +23,7 @@ an existing framework.
2323be used to add WSGI support to a web server or framework. It provides utilities
2424for manipulating WSGI environment variables and response headers, base classes
2525for implementing WSGI servers, a demo HTTP server that serves WSGI applications,
26+ types for static type checking,
2627and a validation tool that checks WSGI servers and applications for conformance
2728to the WSGI specification (:pep: `3333 `).
2829
@@ -43,7 +44,9 @@ This module provides a variety of utility functions for working with WSGI
4344environments. A WSGI environment is a dictionary containing HTTP request
4445variables as described in :pep: `3333 `. All of the functions taking an *environ *
4546parameter expect a WSGI-compliant dictionary to be supplied; please see
46- :pep: `3333 ` for a detailed specification.
47+ :pep: `3333 ` for a detailed specification and
48+ :data: `~wsgiref.types.WSGIEnvironment ` for a type alias that can be used
49+ in type annotations.
4750
4851
4952.. function :: guess_scheme(environ)
@@ -150,7 +153,9 @@ also provides these miscellaneous utilities:
150153
151154.. class :: FileWrapper(filelike, blksize=8192)
152155
153- A wrapper to convert a file-like object to an :term: `iterator `. The resulting objects
156+ A concrete implementation of the :class: `wsgiref.types.FileWrapper `
157+ protocol used to convert a file-like object to an :term: `iterator `.
158+ The resulting objects
154159 are :term: `iterable `\ s. As the object is iterated over, the
155160 optional *blksize * parameter will be repeatedly passed to the *filelike *
156161 object's :meth: `read ` method to obtain bytestrings to yield. When :meth: `read `
@@ -349,7 +354,8 @@ request. (E.g., using the :func:`shift_path_info` function from
349354
350355 .. method :: WSGIRequestHandler.get_environ()
351356
352- Returns a dictionary containing the WSGI environment for a request. The default
357+ Return a :data: `~wsgiref.types.WSGIEnvironment ` dictionary for a
358+ request. The default
353359 implementation copies the contents of the :class: `WSGIServer ` object's
354360 :attr: `base_environ ` dictionary attribute and then adds various headers derived
355361 from the HTTP request. Each call to this method should return a new dictionary
@@ -558,13 +564,15 @@ input, output, and error streams.
558564
559565 .. method :: BaseHandler.get_stdin()
560566
561- Return an input stream object suitable for use as the ``wsgi.input `` of the
567+ Return an object compatible with :class: `~wsgiref.types.InputStream `
568+ suitable for use as the ``wsgi.input `` of the
562569 request currently being processed.
563570
564571
565572 .. method :: BaseHandler.get_stderr()
566573
567- Return an output stream object suitable for use as the ``wsgi.errors `` of the
574+ Return an object compatible with :class: `~wsgiref.types.ErrorStream `
575+ suitable for use as the ``wsgi.errors `` of the
568576 request currently being processed.
569577
570578
@@ -703,8 +711,9 @@ input, output, and error streams.
703711
704712 .. attribute :: BaseHandler.wsgi_file_wrapper
705713
706- A ``wsgi.file_wrapper `` factory, or ``None ``. The default value of this
707- attribute is the :class: `wsgiref.util.FileWrapper ` class.
714+ A ``wsgi.file_wrapper `` factory, compatible with
715+ :class: `wsgiref.types.FileWrapper `, or ``None ``. The default value
716+ of this attribute is the :class: `wsgiref.util.FileWrapper ` class.
708717
709718
710719 .. method :: BaseHandler.sendfile()
@@ -754,6 +763,51 @@ input, output, and error streams.
754763 .. versionadded :: 3.2
755764
756765
766+ :mod: `wsgiref.types ` -- WSGI types for static type checking
767+ -----------------------------------------------------------
768+
769+ .. module :: wsgiref.types
770+ :synopsis: WSGI types for static type checking
771+
772+
773+ This module provides various types for static type checking as described
774+ in :pep: `3333 `.
775+
776+ .. versionadded :: 3.11
777+
778+
779+ .. class :: StartResponse()
780+
781+ A :class: `typing.Protocol ` describing `start_response()
782+ <https://peps.python.org/pep-3333/#the-start-response-callable> `_
783+ callables (:pep: `3333 `).
784+
785+ .. data :: WSGIEnvironment
786+
787+ A type alias describing a WSGI environment dictionary.
788+
789+ .. data :: WSGIApplication
790+
791+ A type alias describing a WSGI application callable.
792+
793+ .. class :: InputStream()
794+
795+ A :class: `typing.Protocol ` describing a `WSGI Input Stream
796+ <https://peps.python.org/pep-3333/#input-and-error-streams> `_.
797+
798+ .. class :: ErrorStream()
799+
800+ A :class: `typing.Protocol ` describing a `WSGI Error Stream
801+ <https://peps.python.org/pep-3333/#input-and-error-streams> `_.
802+
803+ .. class :: FileWrapper()
804+
805+ A :class: `typing.Protocol ` describing a `file wrapper
806+ <https://peps.python.org/pep-3333/#optional-platform-specific-file-handling> `_.
807+ See :class: `wsgiref.util.FileWrapper ` for a concrete implementation of this
808+ protocol.
809+
810+
757811Examples
758812--------
759813
0 commit comments