|
| 1 | +# Type declaration for a WSGI Function in Python 3 |
| 2 | +# |
| 3 | +# wsgiref/types.py doesn't exist and neither does WSGIApplication, it's a type |
| 4 | +# provided for type checking purposes. |
| 5 | +# |
| 6 | +# This means you cannot simply import wsgiref.types in your code. Instead, |
| 7 | +# use the `TYPE_CHECKING` flag from the typing module: |
| 8 | +# |
| 9 | +# from typing import TYPE_CHECKING |
| 10 | +# |
| 11 | +# if TYPE_CHECKING: |
| 12 | +# from wsgiref.types import WSGIApplication |
| 13 | +# |
| 14 | +# This import is now only taken into account by the type checker. Consequently, |
| 15 | +# you need to use 'WSGIApplication' and not simply WSGIApplication when type |
| 16 | +# hinting your code. Otherwise Python will raise NameErrors. |
| 17 | + |
| 18 | +from typing import Callable, Dict, Iterable, List, Optional, Tuple, Type, Union |
| 19 | +from types import TracebackType |
| 20 | + |
| 21 | +_exc_info = Tuple[Optional[Type[BaseException]], |
| 22 | + Optional[BaseException], |
| 23 | + Optional[TracebackType]] |
| 24 | +WSGIApplication = Callable[ |
| 25 | + [ |
| 26 | + Dict[str, str], |
| 27 | + Union[ |
| 28 | + Callable[[str, List[Tuple[str, str]]], Callable[[Union[bytes, str]], None]], |
| 29 | + Callable[[str, List[Tuple[str, str]], _exc_info], Callable[[Union[bytes, str]], None]], |
| 30 | + ] |
| 31 | + ], |
| 32 | + Iterable[Union[bytes, str]], |
| 33 | +] |
0 commit comments