Skip to content

Commit

Permalink
Use __future__.annotations (#2199)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex authored Dec 26, 2023
1 parent e811b4e commit 32fa92f
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 247 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,7 @@ py-gte-38 = "sys_version_info >= (3, 8)"
py-lt-38 = "sys_version_info < (3, 8)"
py-gte-39 = "sys_version_info >= (3, 9)"
py-lt-39 = "sys_version_info < (3, 9)"
py-gte-310 = "sys_version_info >= (3, 10)"
py-lt-310 = "sys_version_info < (3, 10)"
py-gte-311 = "sys_version_info >= (3, 11)"
py-lt-311 = "sys_version_info < (3, 11)"
10 changes: 6 additions & 4 deletions uvicorn/_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
Some light wrappers around Python's multiprocessing, to deal with cleanly
starting child processes.
"""
from __future__ import annotations

import multiprocessing
import os
import sys
from multiprocessing.context import SpawnProcess
from socket import socket
from typing import Callable, List, Optional
from typing import Callable, Optional

from uvicorn.config import Config

Expand All @@ -18,7 +20,7 @@
def get_subprocess(
config: Config,
target: Callable[..., None],
sockets: List[socket],
sockets: list[socket],
) -> SpawnProcess:
"""
Called in the parent process, to instantiate a new child process instance.
Expand Down Expand Up @@ -51,8 +53,8 @@ def get_subprocess(
def subprocess_started(
config: Config,
target: Callable[..., None],
sockets: List[socket],
stdin_fileno: Optional[int],
sockets: list[socket],
stdin_fileno: int | None,
) -> None:
"""
Called when the child process starts.
Expand Down
42 changes: 21 additions & 21 deletions uvicorn/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
from __future__ import annotations

import sys
import types
from typing import (
Any,
Awaitable,
Callable,
Dict,
Iterable,
MutableMapping,
Optional,
Expand Down Expand Up @@ -63,7 +63,7 @@
# ASGI
class ASGIVersions(TypedDict):
spec_version: str
version: Union[Literal["2.0"], Literal["3.0"]]
version: Literal["2.0"] | Literal["3.0"]


class HTTPScope(TypedDict):
Expand All @@ -76,11 +76,11 @@ class HTTPScope(TypedDict):
raw_path: bytes
query_string: bytes
root_path: str
headers: Iterable[Tuple[bytes, bytes]]
client: Optional[Tuple[str, int]]
server: Optional[Tuple[str, Optional[int]]]
state: NotRequired[Dict[str, Any]]
extensions: NotRequired[Dict[str, Dict[object, object]]]
headers: Iterable[tuple[bytes, bytes]]
client: tuple[str, int] | None
server: tuple[str, int | None] | None
state: NotRequired[dict[str, Any]]
extensions: NotRequired[dict[str, dict[object, object]]]


class WebSocketScope(TypedDict):
Expand All @@ -92,18 +92,18 @@ class WebSocketScope(TypedDict):
raw_path: bytes
query_string: bytes
root_path: str
headers: Iterable[Tuple[bytes, bytes]]
client: Optional[Tuple[str, int]]
server: Optional[Tuple[str, Optional[int]]]
headers: Iterable[tuple[bytes, bytes]]
client: tuple[str, int] | None
server: tuple[str, int | None] | None
subprotocols: Iterable[str]
state: NotRequired[Dict[str, Any]]
extensions: NotRequired[Dict[str, Dict[object, object]]]
state: NotRequired[dict[str, Any]]
extensions: NotRequired[dict[str, dict[object, object]]]


class LifespanScope(TypedDict):
type: Literal["lifespan"]
asgi: ASGIVersions
state: NotRequired[Dict[str, Any]]
state: NotRequired[dict[str, Any]]


WWWScope = Union[HTTPScope, WebSocketScope]
Expand All @@ -118,13 +118,13 @@ class HTTPRequestEvent(TypedDict):

class HTTPResponseDebugEvent(TypedDict):
type: Literal["http.response.debug"]
info: Dict[str, object]
info: dict[str, object]


class HTTPResponseStartEvent(TypedDict):
type: Literal["http.response.start"]
status: int
headers: NotRequired[Iterable[Tuple[bytes, bytes]]]
headers: NotRequired[Iterable[tuple[bytes, bytes]]]
trailers: NotRequired[bool]


Expand All @@ -136,14 +136,14 @@ class HTTPResponseBodyEvent(TypedDict):

class HTTPResponseTrailersEvent(TypedDict):
type: Literal["http.response.trailers"]
headers: Iterable[Tuple[bytes, bytes]]
headers: Iterable[tuple[bytes, bytes]]
more_trailers: bool


class HTTPServerPushEvent(TypedDict):
type: Literal["http.response.push"]
path: str
headers: Iterable[Tuple[bytes, bytes]]
headers: Iterable[tuple[bytes, bytes]]


class HTTPDisconnectEvent(TypedDict):
Expand All @@ -156,8 +156,8 @@ class WebSocketConnectEvent(TypedDict):

class WebSocketAcceptEvent(TypedDict):
type: Literal["websocket.accept"]
subprotocol: NotRequired[Optional[str]]
headers: NotRequired[Iterable[Tuple[bytes, bytes]]]
subprotocol: NotRequired[str | None]
headers: NotRequired[Iterable[tuple[bytes, bytes]]]


class _WebSocketReceiveEventBytes(TypedDict):
Expand Down Expand Up @@ -193,7 +193,7 @@ class _WebSocketSendEventText(TypedDict):
class WebSocketResponseStartEvent(TypedDict):
type: Literal["websocket.http.response.start"]
status: int
headers: Iterable[Tuple[bytes, bytes]]
headers: Iterable[tuple[bytes, bytes]]


class WebSocketResponseBodyEvent(TypedDict):
Expand All @@ -210,7 +210,7 @@ class WebSocketDisconnectEvent(TypedDict):
class WebSocketCloseEvent(TypedDict):
type: Literal["websocket.close"]
code: NotRequired[int]
reason: NotRequired[Optional[str]]
reason: NotRequired[str | None]


class LifespanStartupEvent(TypedDict):
Expand Down
Loading

0 comments on commit 32fa92f

Please sign in to comment.