Skip to content

Add type signature for a WSGI Application to wsgiref. #725

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

Closed
wants to merge 3 commits into from
Closed
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
26 changes: 26 additions & 0 deletions stdlib/2/wsgiref/types.pyi
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

typing -> types

# provided for type checking purposes.
#
# To correctly use this type stub, utilize the `TYPE_CHECKING` flag in
Copy link
Member

Choose a reason for hiding this comment

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

utilize -> use

# typing:
#
# from typing import TYPE_CHECKING
#
# if TYPE_CHECKING:
# from wsgiref import WSGIFunction
Copy link
Member

Choose a reason for hiding this comment

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

Change to from wsgiref.types import ...

#

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]]
Copy link
Member

Choose a reason for hiding this comment

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

This is pretty unreadable. Maybe you can clear it up a bit using some more type aliases? (An added benefit might be that there are fewer differences between PY2 and PY3.)

]],
Iterable[Union[unicode, str]]]
26 changes: 26 additions & 0 deletions stdlib/3/wsgiref/types.pyi
Original file line number Diff line number Diff line change
@@ -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
#
Copy link
Member

Choose a reason for hiding this comment

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

In the PY3 version (but not in the PY2 version) you should also tell users to use "forward reference" notation when using this (except in # type: comments). An example would be good.


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]]]