Skip to content

Commit ce54f29

Browse files
author
Roy Williams
committed
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.
1 parent d1081b9 commit ce54f29

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

stdlib/2/wsgiref/__init__.pyi

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Type declaration for a WSGI Function in Python 2
2+
#
3+
# This function actually exist, but we need a central place to define the type
4+
# of a WSGI Application.
5+
#
6+
# To correctly use this type stub, utilize the `TYPE_CHECKING` flag in
7+
# typing:
8+
#
9+
# from typing import TYPE_CHECKING
10+
#
11+
# if TYPE_CHECKING:
12+
# from wsgiref import WSGIFunction
13+
#
14+
15+
from typing import Callable, Iterable, List, Optional, Tuple, Type, Union
16+
from types import TracebackType
17+
18+
exc_info = Tuple[Optional[Type[BaseException]],
19+
Optional[BaseException],
20+
Optional[TracebackType]]
21+
WSGIFunction = Callable[[Dict[Union[unicode, str], Union[unicode, str]],
22+
Union[
23+
Callable[[Text, List[Tuple[Union[unicode, str], Union[unicode, str]]]], Callable[[Union[unicode, str]], None]],
24+
Callable[[Text, List[Tuple[Union[unicode, str], Union[unicode, str]]], exc_info], Callable[[Union[unicode, str]], None]]
25+
]],
26+
Iterable[Union[unicode, str]]]

stdlib/3/wsgiref/__init__.pyi

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Type declaration for a WSGI Function in Python 3
2+
#
3+
# This function actually exist, but we need a central place to define the type
4+
# of a WSGI Application.
5+
#
6+
# To correctly use this type stub, utilize the `TYPE_CHECKING` flag in
7+
# typing:
8+
#
9+
# from typing import TYPE_CHECKING
10+
#
11+
# if TYPE_CHECKING:
12+
# from wsgiref import WSGIFunction
13+
#
14+
15+
from typing import Callable, Iterable, List, Optional, Tuple, Type, Union
16+
from types import TracebackType
17+
18+
exc_info = Tuple[Optional[Type[BaseException]],
19+
Optional[BaseException],
20+
Optional[TracebackType]]
21+
WSGIFunction = Callable[[Dict[Union[bytes, str], Union[bytes, str]],
22+
Union[
23+
Callable[[Text, List[Tuple[Union[bytes, str], Union[bytes, str]]]], Callable[[Union[bytes, str]], None]],
24+
Callable[[Text, List[Tuple[Union[bytes, str], Union[bytes, str]]], exc_info], Callable[[Union[bytes, str]], None]]
25+
]],
26+
Iterable[Union[bytes, str]]]

0 commit comments

Comments
 (0)