Skip to content

Add type signature for a WSGI Application to wsgiref #825

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

Merged
merged 6 commits into from
Jan 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions stdlib/2/wsgiref/types.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Type declaration for a WSGI Function in Python 2
#
# wsgiref/types.py doesn't exist and neither does WSGIApplication, it's a type
# provided for type checking purposes.
#
# This means you cannot simply import wsgiref.types in your code. Instead,
# use the `TYPE_CHECKING` flag from the typing module:
#
# from typing import TYPE_CHECKING
#
# if TYPE_CHECKING:
# from wsgiref.types import WSGIApplication
#
# This import is now only taken into account by the type checker. Consequently,
# you need to use 'WSGIApplication' and not simply WSGIApplication when type
# hinting your code. Otherwise Python will raise NameErrors.

from typing import Callable, Dict, Iterable, List, Optional, Tuple, Type, Union
from types import TracebackType

_exc_info = Tuple[Optional[Type[BaseException]],
Optional[BaseException],
Optional[TracebackType]]
_Text = Union[unicode, str]
WSGIApplication = Callable[
[
Dict[_Text, _Text],
Union[
Callable[[_Text, List[Tuple[_Text, _Text]]], Callable[[_Text], None]],
Callable[[_Text, List[Tuple[_Text, _Text]], _exc_info], Callable[[_Text], None]],
]
],
Iterable[_Text]
]
33 changes: 33 additions & 0 deletions stdlib/3/wsgiref/types.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Type declaration for a WSGI Function in Python 3
#
# wsgiref/types.py doesn't exist and neither does WSGIApplication, it's a type
# provided for type checking purposes.
#
# This means you cannot simply import wsgiref.types in your code. Instead,
# use the `TYPE_CHECKING` flag from the typing module:
#
# from typing import TYPE_CHECKING
#
# if TYPE_CHECKING:
# from wsgiref.types import WSGIApplication
#
# This import is now only taken into account by the type checker. Consequently,
# you need to use 'WSGIApplication' and not simply WSGIApplication when type
# hinting your code. Otherwise Python will raise NameErrors.

from typing import Callable, Dict, 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]],
]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's another one right here ;-)

],
Iterable[Union[bytes, str]],
]