From 81431d21d27d45fd3acd1b8f9131c92aceb8e8b1 Mon Sep 17 00:00:00 2001 From: Roy Williams Date: Wed, 30 Nov 2016 10:48:13 -0800 Subject: [PATCH 1/3] Add type signature for a WSGI Application to wsgiref. This type is something core to Python and is useful when typing web applications, but doesn't actually exist in the stdlib anywhere. I put this in wsgiref, but I am open to suggestions as for a better place. --- stdlib/2/wsgiref/__init__.pyi | 26 ++++++++++++++++++++++++++ stdlib/3/wsgiref/__init__.pyi | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/stdlib/2/wsgiref/__init__.pyi b/stdlib/2/wsgiref/__init__.pyi index e69de29bb2d1..aa6a8fb92d5f 100644 --- a/stdlib/2/wsgiref/__init__.pyi +++ b/stdlib/2/wsgiref/__init__.pyi @@ -0,0 +1,26 @@ +# Type declaration for a WSGI Function in Python 2 +# +# This function actually exist, but we need a central place to define the type +# of a WSGI Application. +# +# To correctly use this type stub, utilize the `TYPE_CHECKING` flag in +# typing: +# +# from typing import TYPE_CHECKING +# +# if TYPE_CHECKING: +# from wsgiref import WSGIFunction +# + +from typing import Callable, Iterable, List, Optional, Tuple, Type, Union +from types import TracebackType + +exc_info = Tuple[Optional[Type[BaseException]], + Optional[BaseException], + Optional[TracebackType]] +WSGIFunction = Callable[[Dict[Union[unicode, str], Union[unicode, str]], + Union[ + Callable[[Union[unicode, str], List[Tuple[Union[unicode, str], Union[unicode, str]]]], Callable[[Union[unicode, str]], None]], + Callable[[Union[unicode, str], List[Tuple[Union[unicode, str], Union[unicode, str]]], exc_info], Callable[[Union[unicode, str]], None]] + ]], + Iterable[Union[unicode, str]]] diff --git a/stdlib/3/wsgiref/__init__.pyi b/stdlib/3/wsgiref/__init__.pyi index e69de29bb2d1..0127d00a7fa2 100644 --- a/stdlib/3/wsgiref/__init__.pyi +++ b/stdlib/3/wsgiref/__init__.pyi @@ -0,0 +1,26 @@ +# Type declaration for a WSGI Function in Python 3 +# +# This function actually exist, but we need a central place to define the type +# of a WSGI Application. +# +# To correctly use this type stub, utilize the `TYPE_CHECKING` flag in +# typing: +# +# from typing import TYPE_CHECKING +# +# if TYPE_CHECKING: +# from wsgiref import WSGIFunction +# + +from typing import Callable, Iterable, List, Optional, Tuple, Type, Union +from types import TracebackType + +exc_info = Tuple[Optional[Type[BaseException]], + Optional[BaseException], + Optional[TracebackType]] +WSGIFunction = Callable[[Dict[str, str], + Union[ + Callable[[str, List[Tuple[str, str]]], Callable[[Union[bytes, str]], None]], + Callable[[str, List[Tuple[str, str]], exc_info], Callable[[Union[bytes, str]], None]] + ]], + Iterable[Union[bytes, str]]] From ad7c4b37f6f868159c52a37b7df747b649e650e1 Mon Sep 17 00:00:00 2001 From: Roy Williams Date: Wed, 30 Nov 2016 12:03:14 -0800 Subject: [PATCH 2/3] s/WSGIFunction/WSGIApplication and fix up comments --- stdlib/2/wsgiref/__init__.pyi | 16 ++++++++-------- stdlib/3/wsgiref/__init__.pyi | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/stdlib/2/wsgiref/__init__.pyi b/stdlib/2/wsgiref/__init__.pyi index aa6a8fb92d5f..c6e1255ba144 100644 --- a/stdlib/2/wsgiref/__init__.pyi +++ b/stdlib/2/wsgiref/__init__.pyi @@ -1,7 +1,7 @@ # Type declaration for a WSGI Function in Python 2 # -# This function actually exist, but we need a central place to define the type -# of a WSGI Application. +# WSGIApplication doesn't exist in wsgiref/__init__.py, it's a type provided for +# type checking purposes. # # To correctly use this type stub, utilize the `TYPE_CHECKING` flag in # typing: @@ -18,9 +18,9 @@ from types import TracebackType exc_info = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]] -WSGIFunction = Callable[[Dict[Union[unicode, str], Union[unicode, str]], - Union[ - Callable[[Union[unicode, str], List[Tuple[Union[unicode, str], Union[unicode, str]]]], Callable[[Union[unicode, str]], None]], - Callable[[Union[unicode, str], List[Tuple[Union[unicode, str], Union[unicode, str]]], exc_info], Callable[[Union[unicode, str]], None]] - ]], - Iterable[Union[unicode, str]]] +WSGIApplication = Callable[[Dict[Union[unicode, str], Union[unicode, str]], + Union[ + Callable[[Union[unicode, str], List[Tuple[Union[unicode, str], Union[unicode, str]]]], Callable[[Union[unicode, str]], None]], + Callable[[Union[unicode, str], List[Tuple[Union[unicode, str], Union[unicode, str]]], exc_info], Callable[[Union[unicode, str]], None]] + ]], + Iterable[Union[unicode, str]]] diff --git a/stdlib/3/wsgiref/__init__.pyi b/stdlib/3/wsgiref/__init__.pyi index 0127d00a7fa2..c06eea73c9ec 100644 --- a/stdlib/3/wsgiref/__init__.pyi +++ b/stdlib/3/wsgiref/__init__.pyi @@ -1,7 +1,7 @@ # Type declaration for a WSGI Function in Python 3 # -# This function actually exist, but we need a central place to define the type -# of a WSGI Application. +# WSGIApplication doesn't exist in wsgiref/__init__.py, it's a type provided for +# type checking purposes. # # To correctly use this type stub, utilize the `TYPE_CHECKING` flag in # typing: @@ -18,9 +18,9 @@ from types import TracebackType exc_info = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]] -WSGIFunction = Callable[[Dict[str, str], - Union[ - Callable[[str, List[Tuple[str, str]]], Callable[[Union[bytes, str]], None]], - Callable[[str, List[Tuple[str, str]], exc_info], Callable[[Union[bytes, str]], None]] - ]], - Iterable[Union[bytes, str]]] +WSGIApplication = Callable[[Dict[str, str], + Union[ + Callable[[str, List[Tuple[str, str]]], Callable[[Union[bytes, str]], None]], + Callable[[str, List[Tuple[str, str]], exc_info], Callable[[Union[bytes, str]], None]] + ]], + Iterable[Union[bytes, str]]] From 7f8b82266bf91e963d8e3cb9b4941732b6607392 Mon Sep 17 00:00:00 2001 From: Roy Williams Date: Wed, 30 Nov 2016 17:30:50 -0800 Subject: [PATCH 3/3] Move WSGIAppliation to wsgiref.types --- stdlib/2/wsgiref/__init__.pyi | 26 -------------------------- stdlib/2/wsgiref/types.pyi | 26 ++++++++++++++++++++++++++ stdlib/3/wsgiref/__init__.pyi | 26 -------------------------- stdlib/3/wsgiref/types.pyi | 26 ++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 52 deletions(-) create mode 100644 stdlib/2/wsgiref/types.pyi create mode 100644 stdlib/3/wsgiref/types.pyi diff --git a/stdlib/2/wsgiref/__init__.pyi b/stdlib/2/wsgiref/__init__.pyi index c6e1255ba144..e69de29bb2d1 100644 --- a/stdlib/2/wsgiref/__init__.pyi +++ b/stdlib/2/wsgiref/__init__.pyi @@ -1,26 +0,0 @@ -# Type declaration for a WSGI Function in Python 2 -# -# WSGIApplication doesn't exist in wsgiref/__init__.py, it's a type provided for -# type checking purposes. -# -# To correctly use this type stub, utilize the `TYPE_CHECKING` flag in -# typing: -# -# from typing import TYPE_CHECKING -# -# if TYPE_CHECKING: -# from wsgiref import WSGIFunction -# - -from typing import Callable, Iterable, List, Optional, Tuple, Type, Union -from types import TracebackType - -exc_info = Tuple[Optional[Type[BaseException]], - Optional[BaseException], - Optional[TracebackType]] -WSGIApplication = Callable[[Dict[Union[unicode, str], Union[unicode, str]], - Union[ - Callable[[Union[unicode, str], List[Tuple[Union[unicode, str], Union[unicode, str]]]], Callable[[Union[unicode, str]], None]], - Callable[[Union[unicode, str], List[Tuple[Union[unicode, str], Union[unicode, str]]], exc_info], Callable[[Union[unicode, str]], None]] - ]], - Iterable[Union[unicode, str]]] diff --git a/stdlib/2/wsgiref/types.pyi b/stdlib/2/wsgiref/types.pyi new file mode 100644 index 000000000000..99a7e73e9c80 --- /dev/null +++ b/stdlib/2/wsgiref/types.pyi @@ -0,0 +1,26 @@ +# Type declaration for a WSGI Function in Python 2 +# +# wsgiref/typing.py doesn't exist and neither does WSGIApplication, it's a type +# provided for type checking purposes. +# +# To correctly use this type stub, utilize the `TYPE_CHECKING` flag in +# typing: +# +# from typing import TYPE_CHECKING +# +# if TYPE_CHECKING: +# from wsgiref import WSGIFunction +# + +from typing import Callable, Iterable, List, Optional, Tuple, Type, Union +from types import TracebackType + +_exc_info = Tuple[Optional[Type[BaseException]], + Optional[BaseException], + Optional[TracebackType]] +WSGIApplication = Callable[[Dict[Union[unicode, str], Union[unicode, str]], + Union[ + Callable[[Union[unicode, str], List[Tuple[Union[unicode, str], Union[unicode, str]]]], Callable[[Union[unicode, str]], None]], + Callable[[Union[unicode, str], List[Tuple[Union[unicode, str], Union[unicode, str]]], _exc_info], Callable[[Union[unicode, str]], None]] + ]], + Iterable[Union[unicode, str]]] diff --git a/stdlib/3/wsgiref/__init__.pyi b/stdlib/3/wsgiref/__init__.pyi index c06eea73c9ec..e69de29bb2d1 100644 --- a/stdlib/3/wsgiref/__init__.pyi +++ b/stdlib/3/wsgiref/__init__.pyi @@ -1,26 +0,0 @@ -# Type declaration for a WSGI Function in Python 3 -# -# WSGIApplication doesn't exist in wsgiref/__init__.py, it's a type provided for -# type checking purposes. -# -# To correctly use this type stub, utilize the `TYPE_CHECKING` flag in -# typing: -# -# from typing import TYPE_CHECKING -# -# if TYPE_CHECKING: -# from wsgiref import WSGIFunction -# - -from typing import Callable, Iterable, List, Optional, Tuple, Type, Union -from types import TracebackType - -exc_info = Tuple[Optional[Type[BaseException]], - Optional[BaseException], - Optional[TracebackType]] -WSGIApplication = Callable[[Dict[str, str], - Union[ - Callable[[str, List[Tuple[str, str]]], Callable[[Union[bytes, str]], None]], - Callable[[str, List[Tuple[str, str]], exc_info], Callable[[Union[bytes, str]], None]] - ]], - Iterable[Union[bytes, str]]] diff --git a/stdlib/3/wsgiref/types.pyi b/stdlib/3/wsgiref/types.pyi new file mode 100644 index 000000000000..8bbc33087ed0 --- /dev/null +++ b/stdlib/3/wsgiref/types.pyi @@ -0,0 +1,26 @@ +# Type declaration for a WSGI Function in Python 3 +# +# wsgiref/typing.py doesn't exist and neither does WSGIApplication, it's a type +# provided for type checking purposes. +# +# To correctly use this type stub, utilize the `TYPE_CHECKING` flag in +# typing: +# +# from typing import TYPE_CHECKING +# +# if TYPE_CHECKING: +# from wsgiref import WSGIFunction +# + +from typing import Callable, Iterable, List, Optional, Tuple, Type, Union +from types import TracebackType + +_exc_info = Tuple[Optional[Type[BaseException]], + Optional[BaseException], + Optional[TracebackType]] +WSGIApplication = Callable[[Dict[str, str], + Union[ + Callable[[str, List[Tuple[str, str]]], Callable[[Union[bytes, str]], None]], + Callable[[str, List[Tuple[str, str]], _exc_info], Callable[[Union[bytes, str]], None]] + ]], + Iterable[Union[bytes, str]]]