Skip to content

Commit 0394026

Browse files
committed
gunicorn, draft
1 parent a5c7752 commit 0394026

File tree

10 files changed

+31
-23
lines changed

10 files changed

+31
-23
lines changed

stubs/gunicorn/gunicorn/_types.pyi

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
### This .pyi file is a helper for centralized storage types that are reused across different runtime modules. ###
2-
from _typeshed import FileDescriptor
2+
from _typeshed import FileDescriptor, OptExcInfo
33
from collections.abc import Awaitable, Callable, Iterable, MutableMapping
4-
from typing import Any
4+
from typing import Any, Protocol
55
from typing_extensions import LiteralString, TypeAlias
66

77
_StatusType: TypeAlias = str
88
_HeadersType: TypeAlias = Iterable[tuple[str, str]]
99

1010
_EnvironType: TypeAlias = MutableMapping[str, Any] # See https://peps.python.org/pep-0333/
11-
_StartResponseType: TypeAlias = Callable[[_StatusType, _HeadersType], None]
11+
class _StartResponseType(Protocol):
12+
def __call__(
13+
self, status: _StatusType, headers: _HeadersType, exc_info: OptExcInfo | None = ..., /
14+
) -> Callable[[bytes], object]: ...
15+
1216
_ResponseBodyType: TypeAlias = Iterable[bytes]
1317
_WSGIAppType: TypeAlias = Callable[[_EnvironType, _StartResponseType], _ResponseBodyType] # noqa: Y047
1418

stubs/gunicorn/gunicorn/debug.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Spew:
1111

1212
def __init__(self, trace_names: Container[str] | None = None, show_values: bool = True) -> None: ...
1313
def __call__(
14-
self, frame: FrameType, event: str, arg: Any # `arg` is not used inside the function, stub is set Any
14+
self, frame: FrameType, event: Literal["call", "line", "return", "exception", "opcode"], arg: Any # `arg` is not used inside the function, stub is set Any
1515
) -> Self: ...
1616

1717
def spew(trace_names: Container[str] | None = None, show_values: bool = False) -> None: ...

stubs/gunicorn/gunicorn/http/wsgi.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import re
44
import socket
55
from _typeshed import ReadableBuffer
66
from collections.abc import Callable
7-
from typing import Any
7+
from typing import Any, Never
88

99
from gunicorn.config import Config
1010
from gunicorn.http import Request
@@ -21,7 +21,7 @@ class FileWrapper:
2121
close: Callable[[], None] | None
2222

2323
def __init__(self, filelike: io.IOBase, blksize: int = 8192) -> None: ...
24-
def __getitem__(self, key: Any) -> bytes: ...
24+
def __getitem__(self, key: Never) -> bytes: ...
2525

2626
class WSGIErrorsWrapper(io.RawIOBase):
2727
streams: list[io.TextIOBase]

stubs/gunicorn/gunicorn/util.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ hop_headers: set[str]
1212

1313
def load_entry_point(distribution: str, group: str, name: str) -> type[object]: ...
1414
def load_class(
15-
uri: str | object, default: str = "gunicorn.workers.sync.SyncWorker", section: str = "gunicorn.workers"
16-
) -> type[Any]: ...
15+
uri: str | type[Logger] | type[SyncWorker], default: str = "gunicorn.workers.sync.SyncWorker", section: str = "gunicorn.workers"
16+
) -> type[Logger] | type[SyncWorker]: ...
1717

1818
positionals: tuple[Literal[_ParameterKind.POSITIONAL_ONLY], Literal[_ParameterKind.POSITIONAL_OR_KEYWORD]]
1919

@@ -30,19 +30,19 @@ def close(sock: socket) -> None: ...
3030
def write_chunk(sock: socket, data: bytes) -> None: ...
3131
def write(sock: socket, data: bytes, chunked: bool = False) -> None: ...
3232
def write_nonblock(sock: socket, data: bytes, chunked: bool = False) -> None: ...
33-
def write_error(sock: socket, status_int: int, reason: str, mesg: str) -> None: ...
33+
def write_error(sock: socket, status_int: int, reason: LiteralString, mesg: str) -> None: ...
3434
def import_app(module: str) -> _WSGIAppType: ...
3535
def getcwd() -> str: ...
3636
def http_date(timestamp: float | None = None) -> str: ...
3737
def is_hoppish(header: str) -> bool: ...
3838
def daemonize(enable_stdio_inheritance: bool = False) -> None: ...
3939
def seed() -> None: ...
4040
def check_is_writable(path: FileDescriptorOrPath) -> None: ...
41-
def to_bytestring(value: str | bytes, encoding: str = "utf8") -> bytes: ...
41+
def to_bytestring(value: str | bytes, encoding: LiteralString = "utf8") -> bytes: ...
4242
def has_fileno(obj: HasFileno) -> bool: ...
4343
def warn(msg: str) -> None: ...
4444
def make_fail_app(msg: str) -> _WSGIAppType: ...
4545
def split_request_uri(uri: str) -> SplitResult: ...
4646
def reraise(tp: type[BaseException], value: BaseException | None, tb: types.TracebackType | None = None) -> NoReturn: ...
47-
def bytes_to_str(b: bytes) -> str: ...
47+
def bytes_to_str(b: bytes | str) -> str: ...
4848
def unquote_to_wsgi_str(string: str) -> str: ...

stubs/gunicorn/gunicorn/workers/base.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Worker:
1919
ppid: int
2020
sockets: list[socket.socket]
2121
app: BaseApplication
22-
timeout: int
22+
timeout: float
2323
cfg: Config
2424
booted: bool
2525
aborted: bool
@@ -33,7 +33,7 @@ class Worker:
3333
wsgi: _WSGIAppType
3434

3535
def __init__(
36-
self, age: int, ppid: int, sockets: list[socket.socket], app: BaseApplication, timeout: int, cfg: Config, log: GLogger
36+
self, age: int, ppid: int, sockets: list[socket.socket], app: BaseApplication, timeout: float, cfg: Config, log: GLogger
3737
) -> None: ...
3838
def notify(self) -> None: ...
3939
def run(self) -> None: ...

stubs/gunicorn/gunicorn/workers/base_async.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import socket
2+
from contextlib import AbstractAsyncContextManager
23

34
from gunicorn.http import Request
45
from gunicorn.workers import base
@@ -11,7 +12,7 @@ class AsyncWorker(base.Worker):
1112
worker_connections: int
1213
alive: bool
1314

14-
def timeout_ctx(self) -> None: ...
15+
def timeout_ctx(self) -> AbstractAsyncContextManager[None]: ...
1516
def is_already_handled(self, respiter: object) -> bool: ...
1617
def handle(self, listener: socket.socket, client: socket.socket, addr: _AddressType) -> None: ...
17-
def handle_request(self, listener_name: str, req: Request, sock: socket.socket, addr: _AddressType) -> bool: ...
18+
def handle_request(self, listener_name: str, req: Request, sock: socket.socket, addr: _AddressType) -> bool | None: ...

stubs/gunicorn/gunicorn/workers/geventlet.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from contextlib import AbstractAsyncContextManager
12
from types import FrameType
23
from typing import Any
34
from typing_extensions import TypeAlias
@@ -19,6 +20,6 @@ class EventletWorker(AsyncWorker):
1920
def init_process(self) -> None: ...
2021
def handle_quit(self, sig: int, frame: FrameType | None) -> None: ...
2122
def handle_usr1(self, sig: int, frame: FrameType | None) -> None: ...
22-
def timeout_ctx(self) -> None: ...
23+
def timeout_ctx(self) -> AbstractAsyncContextManager[None]: ...
2324
def handle(self, listener: GreenSocket, client: GreenSocket, addr: _AddressType) -> None: ...
2425
def run(self) -> None: ...

stubs/gunicorn/gunicorn/workers/ggevent.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from contextlib import AbstractAsyncContextManager
2+
13
from types import FrameType
24
from typing import Any, ClassVar
35

@@ -19,10 +21,10 @@ class GeventWorker(AsyncWorker):
1921

2022
def patch(self) -> None: ...
2123
def notify(self) -> None: ...
22-
def timeout_ctx(self) -> None: ...
24+
def timeout_ctx(self) -> AbstractAsyncContextManager[None]: ...
2325
def run(self) -> None: ...
2426
def handle(self, listener: GeventSocket, client: GeventSocket, addr: _AddressType) -> None: ...
25-
def handle_request(self, listener_name: str, req: Request, sock: GeventSocket, addr: _AddressType) -> bool: ...
27+
def handle_request(self, listener_name: _AddressType, req: Request, sock: GeventSocket, addr: _AddressType) -> bool: ...
2628
def handle_quit(self, sig: int, frame: FrameType | None) -> None: ...
2729
def handle_usr1(self, sig: int, frame: FrameType | None) -> None: ...
2830
def init_process(self) -> None: ...

stubs/gunicorn/gunicorn/workers/gthread.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import socket
22
from collections import deque
33
from concurrent.futures import Future, ThreadPoolExecutor
4-
from selectors import DefaultSelector
4+
from selectors import BaseSelector
55
from types import FrameType
66

77
from gunicorn.config import Config
@@ -29,7 +29,7 @@ class ThreadWorker(base.Worker):
2929
worker_connections: int
3030
max_keepalived: int
3131
tpool: ThreadPoolExecutor
32-
poller: DefaultSelector
32+
poller: BaseSelector
3333
futures: deque[Future[tuple[bool, TConn]]]
3434
nr_conns: int
3535
alive: bool

stubs/gunicorn/gunicorn/workers/sync.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ class StopWaiting(Exception): ...
99

1010
class SyncWorker(Worker):
1111
def accept(self, listener: socket.socket) -> None: ...
12-
def wait(self, timeout: int) -> list[socket.socket | int] | None: ...
12+
def wait(self, timeout: float) -> list[socket.socket]: ...
1313
def is_parent_alive(self) -> bool: ...
14-
def run_for_one(self, timeout: int) -> None: ...
15-
def run_for_multiple(self, timeout: int) -> None: ...
14+
def run_for_one(self, timeout: float) -> None: ...
15+
def run_for_multiple(self, timeout: float) -> None: ...
1616
def run(self) -> None: ...
1717
def handle(self, listener: socket.socket, client: socket.socket, addr: _AddressType) -> None: ...
1818
def handle_request(self, listener: socket.socket, req: Request, client: socket.socket, addr: tuple[str, int]) -> bool: ...

0 commit comments

Comments
 (0)