From a013e0f1c9b77d634def1f15fb083be35a25d5bf Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 12 Nov 2022 18:04:42 -0500 Subject: [PATCH 1/2] Run stubtest on Windows for waitress --- stubs/waitress/@tests/stubtest_allowlist.txt | 1 - .../@tests/stubtest_allowlist_darwin.txt | 1 + .../@tests/stubtest_allowlist_linux.txt | 1 + stubs/waitress/METADATA.toml | 4 ++ stubs/waitress/waitress/server.pyi | 37 ++++++++++--------- stubs/waitress/waitress/wasyncore.pyi | 36 +++++++++--------- 6 files changed, 44 insertions(+), 36 deletions(-) create mode 100644 stubs/waitress/@tests/stubtest_allowlist_darwin.txt create mode 100644 stubs/waitress/@tests/stubtest_allowlist_linux.txt diff --git a/stubs/waitress/@tests/stubtest_allowlist.txt b/stubs/waitress/@tests/stubtest_allowlist.txt index 8468ef5449e1..ed036f64b0f3 100644 --- a/stubs/waitress/@tests/stubtest_allowlist.txt +++ b/stubs/waitress/@tests/stubtest_allowlist.txt @@ -27,7 +27,6 @@ waitress.rfc7230.tobytes waitress.server.BaseWSGIServer.channel_class waitress.server.BaseWSGIServer.get_server_name waitress.server.MultiSocketServer.__init__ -waitress.server.UnixWSGIServer.get_server_name waitress.server.WSGIServer waitress.task.ErrorTask.content_length waitress.task.ThreadedTaskDispatcher.start_new_thread diff --git a/stubs/waitress/@tests/stubtest_allowlist_darwin.txt b/stubs/waitress/@tests/stubtest_allowlist_darwin.txt new file mode 100644 index 000000000000..3aad82a7a12d --- /dev/null +++ b/stubs/waitress/@tests/stubtest_allowlist_darwin.txt @@ -0,0 +1 @@ +waitress.server.UnixWSGIServer.get_server_name diff --git a/stubs/waitress/@tests/stubtest_allowlist_linux.txt b/stubs/waitress/@tests/stubtest_allowlist_linux.txt new file mode 100644 index 000000000000..3aad82a7a12d --- /dev/null +++ b/stubs/waitress/@tests/stubtest_allowlist_linux.txt @@ -0,0 +1 @@ +waitress.server.UnixWSGIServer.get_server_name diff --git a/stubs/waitress/METADATA.toml b/stubs/waitress/METADATA.toml index 91331cf6a90c..9f3f23989697 100644 --- a/stubs/waitress/METADATA.toml +++ b/stubs/waitress/METADATA.toml @@ -1,2 +1,6 @@ version = "2.1.*" requires = [] + +[tool.stubtest] +# linux and darwin are equivalent +platforms = ["linux", "win32"] diff --git a/stubs/waitress/waitress/server.pyi b/stubs/waitress/waitress/server.pyi index e8cb00ae2b2d..d74c12024fc0 100644 --- a/stubs/waitress/waitress/server.pyi +++ b/stubs/waitress/waitress/server.pyi @@ -1,13 +1,13 @@ +import sys from collections.abc import Sequence from socket import socket from typing import Any +from waitress import wasyncore from waitress.adjustments import Adjustments from waitress.channel import HTTPChannel from waitress.task import Task, ThreadedTaskDispatcher -from . import wasyncore - def create_server( application: Any, map: Any | None = ..., @@ -84,21 +84,22 @@ class TcpWSGIServer(BaseWSGIServer): def getsockname(self) -> tuple[str, tuple[str, int]]: ... def set_socket_options(self, conn: socket) -> None: ... -class UnixWSGIServer(BaseWSGIServer): - def __init__( - self, - application: Any, - map: Any | None = ..., - _start: bool = ..., - _sock: Any | None = ..., - dispatcher: Any | None = ..., - adj: Adjustments | None = ..., - sockinfo: Any | None = ..., - **kw: Any, - ) -> None: ... - def bind_server_socket(self) -> None: ... - def getsockname(self) -> tuple[str, tuple[str, int]]: ... - def fix_addr(self, addr: Any) -> tuple[str, None]: ... - def get_server_name(self, ip: Any) -> str: ... +if sys.platform != "win32": + class UnixWSGIServer(BaseWSGIServer): + def __init__( + self, + application: Any, + map: Any | None = ..., + _start: bool = ..., + _sock: Any | None = ..., + dispatcher: Any | None = ..., + adj: Adjustments | None = ..., + sockinfo: Any | None = ..., + **kw: Any, + ) -> None: ... + def bind_server_socket(self) -> None: ... + def getsockname(self) -> tuple[str, tuple[str, int]]: ... + def fix_addr(self, addr: Any) -> tuple[str, None]: ... + def get_server_name(self, ip: Any) -> str: ... WSGIServer: TcpWSGIServer diff --git a/stubs/waitress/waitress/wasyncore.pyi b/stubs/waitress/waitress/wasyncore.pyi index 0338799fe8e5..fee6d61f8434 100644 --- a/stubs/waitress/waitress/wasyncore.pyi +++ b/stubs/waitress/waitress/wasyncore.pyi @@ -1,3 +1,4 @@ +import sys from collections.abc import Callable, Mapping from io import BytesIO from logging import Logger @@ -5,7 +6,7 @@ from socket import socket from typing import Any from typing_extensions import TypeAlias -from . import compat as compat, utilities as utilities +from waitress import compat as compat, utilities as utilities _Socket: TypeAlias = socket @@ -77,20 +78,21 @@ class dispatcher_with_send(dispatcher): def close_all(map: Mapping[int, socket] | None = ..., ignore_all: bool = ...) -> None: ... -class file_wrapper: - fd: BytesIO = ... - def __init__(self, fd: BytesIO) -> None: ... - def __del__(self) -> None: ... - def recv(self, *args: Any) -> bytes: ... - def send(self, *args: Any) -> bytes: ... - def getsockopt(self, level: int, optname: int, buflen: bool | None = ...) -> int: ... - read: Callable[..., bytes] = ... - write: Callable[..., bytes] = ... - def close(self) -> None: ... - def fileno(self) -> BytesIO: ... +if sys.platform == "linux" or sys.platform == "darwin": + class file_wrapper: + fd: BytesIO = ... + def __init__(self, fd: BytesIO) -> None: ... + def __del__(self) -> None: ... + def recv(self, *args: Any) -> bytes: ... + def send(self, *args: Any) -> bytes: ... + def getsockopt(self, level: int, optname: int, buflen: bool | None = ...) -> int: ... + read: Callable[..., bytes] = ... + write: Callable[..., bytes] = ... + def close(self) -> None: ... + def fileno(self) -> BytesIO: ... -class file_dispatcher(dispatcher): - connected: bool = ... - def __init__(self, fd: BytesIO, map: Mapping[int, _Socket] | None = ...) -> None: ... - socket: _Socket = ... - def set_file(self, fd: BytesIO) -> None: ... + class file_dispatcher(dispatcher): + connected: bool = ... + def __init__(self, fd: BytesIO, map: Mapping[int, _Socket] | None = ...) -> None: ... + socket: _Socket = ... + def set_file(self, fd: BytesIO) -> None: ... From f99ca2f1194d90148374a4b1a1190abc7992d569 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 13 Nov 2022 03:09:48 -0500 Subject: [PATCH 2/2] Updated platform check --- stubs/waitress/waitress/trigger.pyi | 4 ++-- stubs/waitress/waitress/wasyncore.pyi | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stubs/waitress/waitress/trigger.pyi b/stubs/waitress/waitress/trigger.pyi index 8736ece99a7f..45d1a40dc230 100644 --- a/stubs/waitress/waitress/trigger.pyi +++ b/stubs/waitress/waitress/trigger.pyi @@ -4,7 +4,7 @@ from socket import socket from threading import Lock from typing_extensions import Literal -from . import wasyncore as wasyncore +from waitress import wasyncore as wasyncore class _triggerbase: kind: str | None = ... @@ -18,7 +18,7 @@ class _triggerbase: def pull_trigger(self, thunk: Callable[[None], object] | None = ...) -> None: ... def handle_read(self) -> None: ... -if sys.platform == "linux" or sys.platform == "darwin": +if sys.platform != "win32": class trigger(_triggerbase, wasyncore.file_dispatcher): kind: str = ... def __init__(self, map: Mapping[str, _triggerbase]) -> None: ... diff --git a/stubs/waitress/waitress/wasyncore.pyi b/stubs/waitress/waitress/wasyncore.pyi index fee6d61f8434..0125447f3125 100644 --- a/stubs/waitress/waitress/wasyncore.pyi +++ b/stubs/waitress/waitress/wasyncore.pyi @@ -78,7 +78,7 @@ class dispatcher_with_send(dispatcher): def close_all(map: Mapping[int, socket] | None = ..., ignore_all: bool = ...) -> None: ... -if sys.platform == "linux" or sys.platform == "darwin": +if sys.platform != "win32": class file_wrapper: fd: BytesIO = ... def __init__(self, fd: BytesIO) -> None: ...