Skip to content
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

Cover httptools_impl on mypy #1102

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8114674
added typing
jkklapp Apr 5, 2021
5603eb5
add file in mypy checks
jkklapp Apr 5, 2021
641f57e
fixed some mypy issues
jkklapp Apr 5, 2021
b77075c
more fixes
jkklapp Apr 5, 2021
1496af9
remove unused import
jkklapp Apr 5, 2021
d5f06fe
fix issue with timeout_keep_alive_task
jkklapp Apr 5, 2021
6675de3
init to None
jkklapp Apr 5, 2021
2e3f97a
fix access_log type
jkklapp Apr 5, 2021
4562a47
fix issue with scope
jkklapp Apr 5, 2021
eaa2996
fix more issues
jkklapp Apr 5, 2021
daf2447
fix scope parameter
jkklapp Apr 5, 2021
8668afb
make headers a dict
jkklapp Apr 5, 2021
29bfbae
use only httpscope
jkklapp Apr 5, 2021
47f1617
fixed typing of chunked_encoding
jkklapp Apr 5, 2021
edf38f5
set exc to Any
jkklapp Apr 5, 2021
b68ddb7
use headers as list
jkklapp Apr 5, 2021
43aa456
fix interpolation issues
jkklapp Apr 5, 2021
b69a5bf
remove unused imports
jkklapp Apr 5, 2021
1bec6f8
init cycle to None
jkklapp Apr 5, 2021
39017d2
ignore remaining issues
jkklapp Apr 5, 2021
fd63a27
sort imports
jkklapp Apr 5, 2021
8230f4a
fixed types in send and receive
jkklapp Apr 10, 2021
d963b2c
add optional to _loop param
jkklapp Apr 10, 2021
53a0814
use new types for receive and send typing
jkklapp Apr 10, 2021
22a30ca
fix on_response init typing
jkklapp Apr 11, 2021
034c0e4
fix scope typing
jkklapp Apr 11, 2021
2d1d0fc
:rotating_light: Cover httptools_impl on mypy
Kludex Jun 29, 2021
b717401
merge master
Kludex Jun 29, 2021
2ba089f
finally
Kludex Jul 9, 2021
348e380
fix on 3.6
Kludex Jul 9, 2021
7083c26
fix on 3.7
Kludex Jul 9, 2021
130e96b
fix wrong merge
Kludex Jul 9, 2021
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
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ files =
uvicorn/middleware/__init__.py,
uvicorn/protocols/__init__.py,
uvicorn/protocols/http/__init__.py,
uvicorn/protocols/websockets/__init__.py
uvicorn/protocols/websockets/__init__.py,
uvicorn/protocols/http/httptools_impl.py


[mypy-tests.*]
Expand Down
52 changes: 41 additions & 11 deletions uvicorn/_types.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
import asyncio
import types
import typing
from typing import (
TYPE_CHECKING,
Any,
Callable,
Iterable,
MutableMapping,
Optional,
Protocol,
Tuple,
Type,
Union,
)

if TYPE_CHECKING:
from uvicorn.config import Config
from uvicorn.server_state import ServerState

# WSGI
Environ = typing.MutableMapping[str, typing.Any]
ExcInfo = typing.Tuple[
typing.Type[BaseException], BaseException, typing.Optional[types.TracebackType]
]
StartResponse = typing.Callable[
[str, typing.Iterable[typing.Tuple[str, str]], typing.Optional[ExcInfo]], None
]
WSGIApp = typing.Callable[
[Environ, StartResponse], typing.Union[typing.Iterable[bytes], BaseException]
]
Environ = MutableMapping[str, Any]
ExcInfo = Tuple[Type[BaseException], BaseException, Optional[types.TracebackType]]
StartResponse = Callable[[str, Iterable[Tuple[str, str]], Optional[ExcInfo]], None]
WSGIApp = Callable[[Environ, StartResponse], Union[Iterable[bytes], BaseException]]


class WebProtocol(Protocol):
Copy link
Member Author

Choose a reason for hiding this comment

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

Here, I'm not sure if we should actually call it WebProtocolProtocol, because the Protocol is from typing. 🤔

def __init__(
self,
config: "Config",
server_state: "ServerState",
on_connection_lost: Optional[Callable[..., Any]],
_loop: Optional[asyncio.AbstractEventLoop] = None,
) -> None:
...

def connection_made(self, transport) -> None:
...

def data_received(self, data: bytes) -> None:
...

def shutdown(self) -> None:
...
9 changes: 6 additions & 3 deletions uvicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys
from typing import Awaitable, Callable, Dict, List, Optional, Tuple, Type, Union

from uvicorn._types import WebProtocol
from uvicorn.logging import TRACE_LOG_LEVEL

if sys.version_info < (3, 8):
Expand Down Expand Up @@ -134,6 +135,8 @@ def create_ssl_context(


class Config:
ws_protocol_class: Type[WebProtocol]

def __init__(
self,
app: Union[ASGIApplication, Callable, str],
Expand All @@ -143,7 +146,7 @@ def __init__(
fd: Optional[int] = None,
loop: LoopSetupType = "auto",
http: Union[Type[asyncio.Protocol], HTTPProtocolType] = "auto",
ws: Union[Type[asyncio.Protocol], WSProtocolType] = "auto",
ws: Union[Type[WebProtocol], WSProtocolType] = "auto",
ws_max_size: int = 16 * 1024 * 1024,
ws_ping_interval: int = 20,
ws_ping_timeout: int = 20,
Expand Down Expand Up @@ -337,7 +340,7 @@ def load(self) -> None:

if isinstance(self.ws, str):
ws_protocol_class = import_from_string(WS_PROTOCOLS[self.ws])
self.ws_protocol_class: Optional[Type[asyncio.Protocol]] = ws_protocol_class
self.ws_protocol_class = ws_protocol_class
else:
self.ws_protocol_class = self.ws

Expand Down Expand Up @@ -374,7 +377,7 @@ def load(self) -> None:

if self.interface == "wsgi":
self.loaded_app = WSGIMiddleware(self.loaded_app)
self.ws_protocol_class = None
self.ws_protocol_class = None # type: ignore[assignment]
elif self.interface == "asgi2":
self.loaded_app = ASGI2Middleware(self.loaded_app)

Expand Down
Loading