diff --git a/stubs/gevent/@tests/stubtest_allowlist.txt b/stubs/gevent/@tests/stubtest_allowlist.txt index e105400f2..80ac846cd 100644 --- a/stubs/gevent/@tests/stubtest_allowlist.txt +++ b/stubs/gevent/@tests/stubtest_allowlist.txt @@ -221,3 +221,7 @@ gevent._types # useful way to use it as a keyword argument; we mark it positional-only. gevent.pool.GroupMappingMixin.imap gevent.pool.GroupMappingMixin.imap_unordered + +# Importing gevent.monkey.__main__ leads to issues in stubtest, since gevent will +# try to monkeypatch stubtest +gevent.monkey.__main__ diff --git a/stubs/gevent/METADATA.toml b/stubs/gevent/METADATA.toml index c956c3743..1db1f9d5c 100644 --- a/stubs/gevent/METADATA.toml +++ b/stubs/gevent/METADATA.toml @@ -1,4 +1,4 @@ -version = "24.2.*" +version = "24.10.*" upstream_repository = "https://github.com/gevent/gevent" requires = ["types-greenlet", "types-psutil"] diff --git a/stubs/gevent/gevent/monkey.pyi b/stubs/gevent/gevent/monkey/__init__.pyi similarity index 86% rename from stubs/gevent/gevent/monkey.pyi rename to stubs/gevent/gevent/monkey/__init__.pyi index 57c992e94..d7ccf4f28 100644 --- a/stubs/gevent/gevent/monkey.pyi +++ b/stubs/gevent/gevent/monkey/__init__.pyi @@ -1,12 +1,11 @@ -from types import ModuleType from typing import Any +from gevent.monkey.api import get_original as get_original, patch_module as patch_module + class MonkeyPatchWarning(RuntimeWarning): ... def is_module_patched(mod_name: str) -> bool: ... def is_object_patched(mod_name: str, item_name: str) -> bool: ... -def get_original(mod_name: str, item_name: str) -> Any: ... -def patch_module(target_module: ModuleType, source_module: ModuleType, items: list[str] | None = None) -> bool: ... def patch_os() -> None: ... def patch_queue() -> None: ... def patch_time() -> None: ... diff --git a/stubs/gevent/gevent/monkey/api.pyi b/stubs/gevent/gevent/monkey/api.pyi new file mode 100644 index 000000000..130687dec --- /dev/null +++ b/stubs/gevent/gevent/monkey/api.pyi @@ -0,0 +1,7 @@ +from types import ModuleType +from typing import Any + +def get_original(mod_name: str, item_name: str) -> Any: ... +def patch_item(module: ModuleType, attr: str, newitem: object) -> None: ... +def remove_item(module: ModuleType, attr: str) -> None: ... +def patch_module(target_module: ModuleType, source_module: ModuleType, items: list[str] | None = None) -> bool: ... diff --git a/stubs/gevent/gevent/queue.pyi b/stubs/gevent/gevent/queue.pyi index f8327e9f2..515aae6f5 100644 --- a/stubs/gevent/gevent/queue.pyi +++ b/stubs/gevent/gevent/queue.pyi @@ -1,3 +1,4 @@ +import sys from collections import deque from collections.abc import Iterable @@ -9,7 +10,12 @@ from typing_extensions import Self from gevent._waiter import Waiter from gevent.hub import Hub -__all__ = ["Queue", "PriorityQueue", "LifoQueue", "SimpleQueue", "JoinableQueue", "Channel", "Empty", "Full"] +__all__ = ["Queue", "PriorityQueue", "LifoQueue", "SimpleQueue", "JoinableQueue", "Channel", "Empty", "Full", "ShutDown"] + +if sys.version_info >= (3, 13): + from queue import ShutDown as ShutDown +else: + class ShutDown(Exception): ... _T = TypeVar("_T") @@ -19,6 +25,7 @@ class Queue(Generic[_T]): @property def queue(self) -> deque[_T]: ... # readonly in Cython maxsize: int | None + is_shutdown: bool @overload def __init__(self, maxsize: int | None = None) -> None: ... @overload @@ -35,6 +42,7 @@ class Queue(Generic[_T]): def put(self, item: _T, block: bool = True, timeout: float | None = None) -> None: ... def put_nowait(self, item: _T) -> None: ... def qsize(self) -> int: ... + def shutdown(self, immediate: bool = False) -> None: ... def __bool__(self) -> bool: ... def __iter__(self) -> Self: ... def __len__(self) -> int: ... diff --git a/stubs/gevent/gevent/timeout.pyi b/stubs/gevent/gevent/timeout.pyi index 341fd2479..9e7bf5e4c 100644 --- a/stubs/gevent/gevent/timeout.pyi +++ b/stubs/gevent/gevent/timeout.pyi @@ -1,6 +1,6 @@ from collections.abc import Callable from types import TracebackType -from typing import Any, Literal, TypeVar, overload +from typing import Any, Literal, Protocol, TypeVar, overload from typing_extensions import ParamSpec, Self from gevent._types import _TimerWatcher @@ -11,6 +11,10 @@ _T2 = TypeVar("_T2") _TimeoutT = TypeVar("_TimeoutT", bound=Timeout) _P = ParamSpec("_P") +class _HasSeconds(Protocol): + @property + def seconds(self) -> float | int: ... + class Timeout(BaseException): seconds: float | None exception: type[BaseException] | BaseException | None @@ -39,6 +43,7 @@ class Timeout(BaseException): def __exit__( self, typ: type[BaseException] | None, value: BaseException | None, tb: TracebackType | None ) -> Literal[True] | None: ... + def __lt__(self, other: _HasSeconds | float) -> bool: ... # when timeout_value is provided we unfortunately get no type checking on *args, **kwargs, because # ParamSpec does not allow mixing in additional keyword arguments