Skip to content

Commit da93072

Browse files
Add stubs for gunicorn (#14690)
1 parent fb852f9 commit da93072

37 files changed

+2280
-0
lines changed

pyrightconfig.stricter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"stubs/grpcio-reflection/grpc_reflection/v1alpha",
4545
"stubs/grpcio-status/grpc_status",
4646
"stubs/grpcio/grpc/__init__.pyi",
47+
"stubs/gunicorn",
4748
"stubs/hdbcli/hdbcli/dbapi.pyi",
4849
"stubs/html5lib",
4950
"stubs/httplib2",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Is not present in runtime. For more details, see the file itself.
2+
gunicorn._types
3+
4+
# .pyi file doesn't exist
5+
gunicorn.__main__

stubs/gunicorn/METADATA.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version = "23.0.*"
2+
upstream_repository = "https://github.com/benoitc/gunicorn"
3+
requires = ["types-gevent"]
4+
5+
[tool.stubtest]
6+
supported_platforms = ["linux", "darwin"]
7+
ci_platforms = ["linux", "darwin"]
8+
stubtest_requirements = ["gevent>=1.4.0", "eventlet>=0.24.1,!=0.36.0", "tornado>=0.2", "setproctitle", "PasteDeploy", "inotify"]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version_info: tuple[int, int, int]
2+
__version__: str
3+
SERVER: str
4+
SERVER_SOFTWARE: str

stubs/gunicorn/gunicorn/_types.pyi

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
### This .pyi file is a helper for centralized storage types that are reused across different runtime modules. ###
2+
from _typeshed import FileDescriptor
3+
from collections.abc import Awaitable, Callable, Iterable, MutableMapping
4+
from typing import Any
5+
from typing_extensions import LiteralString, TypeAlias
6+
7+
_StatusType: TypeAlias = str
8+
_HeadersType: TypeAlias = Iterable[tuple[str, str]]
9+
10+
_EnvironType: TypeAlias = MutableMapping[str, Any] # See https://peps.python.org/pep-0333/
11+
_StartResponseType: TypeAlias = Callable[[_StatusType, _HeadersType], None]
12+
_ResponseBodyType: TypeAlias = Iterable[bytes]
13+
_WSGIAppType: TypeAlias = Callable[[_EnvironType, _StartResponseType], _ResponseBodyType] # noqa: Y047
14+
15+
_ScopeType: TypeAlias = MutableMapping[str, Any]
16+
_MessageType: TypeAlias = MutableMapping[str, Any]
17+
_ReceiveType: TypeAlias = Callable[[], Awaitable[_MessageType]]
18+
_SendType: TypeAlias = Callable[[_MessageType], Awaitable[None]]
19+
_ASGIAppType: TypeAlias = Callable[[_ScopeType, _ReceiveType, _SendType], Awaitable[None]] # noqa: Y047
20+
21+
_UnixSocketPathType: TypeAlias = str
22+
_TcpAddressType: TypeAlias = tuple[LiteralString, int] # noqa: Y047
23+
_AddressType: TypeAlias = _UnixSocketPathType | FileDescriptor | _TcpAddressType # noqa: Y047

stubs/gunicorn/gunicorn/app/__init__.pyi

Whitespace-only changes.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from argparse import ArgumentParser, Namespace
2+
from typing import Any
3+
from typing_extensions import override
4+
5+
from gunicorn.config import Config
6+
from gunicorn.glogging import Logger as GLogger
7+
8+
from .._types import _ASGIAppType, _WSGIAppType
9+
10+
class BaseApplication:
11+
usage: str | None
12+
cfg: Config
13+
callable: _WSGIAppType | _ASGIAppType | None
14+
prog: str | None
15+
logger: GLogger
16+
17+
def __init__(self, usage: str | None = None, prog: str | None = None) -> None: ...
18+
def do_load_config(self) -> None: ...
19+
def load_default_config(self) -> None: ...
20+
def init(self, parser: ArgumentParser, opts: Namespace, args: list[str]) -> dict[str, Any] | None: ...
21+
def load(self) -> _WSGIAppType | _ASGIAppType: ...
22+
def load_config(self) -> None: ...
23+
def reload(self) -> None: ...
24+
def wsgi(self) -> _WSGIAppType | _ASGIAppType: ...
25+
def run(self) -> None: ...
26+
27+
class Application(BaseApplication):
28+
def chdir(self) -> None: ...
29+
def get_config_from_filename(self, filename: str) -> dict[str, Any]: ...
30+
def get_config_from_module_name(self, module_name: str) -> dict[str, Any]: ...
31+
def load_config_from_module_name_or_filename(self, location: str) -> dict[str, Any]: ...
32+
def load_config_from_file(self, filename: str) -> dict[str, Any]: ...
33+
@override
34+
def load_config(self) -> None: ...
35+
@override
36+
def run(self) -> None: ...
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from typing import Any
2+
3+
from .._types import _WSGIAppType
4+
5+
def get_wsgi_app(config_uri: str, name: str | None = None, defaults: dict[str, Any] | None = None) -> _WSGIAppType: ...
6+
def has_logging_config(config_file: str) -> bool: ...
7+
def serve(app: _WSGIAppType, global_conf: dict[str, Any], **local_conf: Any) -> None: ...
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from argparse import ArgumentParser, Namespace
2+
from typing_extensions import override
3+
4+
from gunicorn.app.base import Application
5+
6+
from .._types import _WSGIAppType
7+
8+
class WSGIApplication(Application):
9+
app_uri: str | None
10+
11+
@override
12+
def init(self, parser: ArgumentParser, opts: Namespace, args: list[str]) -> None: ...
13+
@override
14+
def load_config(self) -> None: ...
15+
def load_wsgiapp(self) -> _WSGIAppType: ...
16+
def load_pasteapp(self) -> _WSGIAppType: ...
17+
@override
18+
def load(self) -> _WSGIAppType: ...
19+
20+
def run(prog: str | None = None) -> None: ...
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import socket
2+
from types import FrameType
3+
from typing import ClassVar
4+
5+
from gunicorn.app.base import BaseApplication
6+
from gunicorn.config import Config
7+
from gunicorn.glogging import Logger as GLogger
8+
from gunicorn.workers.base import Worker
9+
10+
from ._types import _AddressType
11+
from .pidfile import Pidfile
12+
13+
class Arbiter:
14+
WORKER_BOOT_ERROR: ClassVar[int]
15+
APP_LOAD_ERROR: ClassVar[int]
16+
START_CTX: ClassVar[dict[int | str, str | list[str]]]
17+
LISTENERS: ClassVar[list[socket.socket]]
18+
WORKERS: ClassVar[dict[int, Worker]]
19+
PIPE: ClassVar[list[int]]
20+
SIG_QUEUE: ClassVar[list[int]]
21+
SIGNALS: ClassVar[list[int]]
22+
SIG_NAMES: ClassVar[dict[int, str]]
23+
log: GLogger | None
24+
pidfile: Pidfile | None
25+
systemd: bool
26+
worker_age: int
27+
reexec_pid: int
28+
master_pid: int
29+
master_name: str
30+
pid: int
31+
app: BaseApplication
32+
cfg: Config
33+
worker_class: type[Worker]
34+
address: list[_AddressType]
35+
timeout: int
36+
proc_name: str
37+
num_workers: int
38+
39+
def __init__(self, app: BaseApplication) -> None: ...
40+
def setup(self, app: BaseApplication) -> None: ...
41+
def start(self) -> None: ...
42+
def init_signals(self) -> None: ...
43+
def signal(self, sig: int, frame: FrameType | None) -> None: ...
44+
def run(self) -> None: ...
45+
def handle_chld(self, sig: int, frame: FrameType | None) -> None: ...
46+
def handle_hup(self) -> None: ...
47+
def handle_term(self) -> None: ...
48+
def handle_int(self) -> None: ...
49+
def handle_quit(self) -> None: ...
50+
def handle_ttin(self) -> None: ...
51+
def handle_ttou(self) -> None: ...
52+
def handle_usr1(self) -> None: ...
53+
def handle_usr2(self) -> None: ...
54+
def handle_winch(self) -> None: ...
55+
def maybe_promote_master(self) -> None: ...
56+
def wakeup(self) -> None: ...
57+
def halt(self, reason: str | None = None, exit_status: int = 0) -> None: ...
58+
def sleep(self) -> None: ...
59+
def stop(self, graceful: bool = True) -> None: ...
60+
def reexec(self) -> None: ...
61+
def reload(self) -> None: ...
62+
def murder_workers(self) -> None: ...
63+
def reap_workers(self) -> None: ...
64+
def manage_workers(self) -> None: ...
65+
def spawn_worker(self) -> int: ...
66+
def spawn_workers(self) -> None: ...
67+
def kill_workers(self, sig: int) -> None: ...
68+
def kill_worker(self, pid: int, sig: int) -> None: ...

0 commit comments

Comments
 (0)