From 66a229b709a23bca83ad936ddeda26f3ead163b5 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 14 Feb 2022 19:09:52 +0000 Subject: [PATCH] stdlib: Add several missing comparison methods (#7202) --- stdlib/asyncio/events.pyi | 5 +++++ stdlib/collections/__init__.pyi | 8 ++++++++ stdlib/tracemalloc.pyi | 20 +++++++++++++++++++- stdlib/urllib/request.pyi | 1 + stdlib/xml/etree/ElementTree.pyi | 4 ++++ 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index 491410977..c86c0a991 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -55,6 +55,11 @@ class TimerHandle(Handle): if sys.version_info >= (3, 7): def when(self) -> float: ... + def __lt__(self, other: TimerHandle) -> bool: ... + def __le__(self, other: TimerHandle) -> bool: ... + def __gt__(self, other: TimerHandle) -> bool: ... + def __ge__(self, other: TimerHandle) -> bool: ... + class AbstractServer: @abstractmethod def close(self) -> None: ... diff --git a/stdlib/collections/__init__.pyi b/stdlib/collections/__init__.pyi index 36849f40a..5b8fdbe01 100644 --- a/stdlib/collections/__init__.pyi +++ b/stdlib/collections/__init__.pyi @@ -220,6 +220,10 @@ class deque(MutableSequence[_T], Generic[_T]): def __add__(self: Self, __other: Self) -> Self: ... def __mul__(self: Self, __other: int) -> Self: ... def __imul__(self: Self, __other: int) -> Self: ... + def __lt__(self, __other: deque[_T]) -> bool: ... + def __le__(self, __other: deque[_T]) -> bool: ... + def __gt__(self, __other: deque[_T]) -> bool: ... + def __ge__(self, __other: deque[_T]) -> bool: ... if sys.version_info >= (3, 9): def __class_getitem__(cls, __item: Any) -> GenericAlias: ... @@ -266,6 +270,10 @@ class Counter(dict[_T, int], Generic[_T]): def __ior__(self: Self, other: Counter[_T]) -> Self: ... # type: ignore[override] if sys.version_info >= (3, 10): def total(self) -> int: ... + def __le__(self, other: Counter[object]) -> bool: ... + def __lt__(self, other: Counter[object]) -> bool: ... + def __ge__(self, other: Counter[object]) -> bool: ... + def __gt__(self, other: Counter[object]) -> bool: ... @final class _OrderedDictKeysView(dict_keys[_KT_co, _VT_co], Reversible[_KT_co]): # type: ignore[misc] diff --git a/stdlib/tracemalloc.pyi b/stdlib/tracemalloc.pyi index 0af707bb5..3b6e7f676 100644 --- a/stdlib/tracemalloc.pyi +++ b/stdlib/tracemalloc.pyi @@ -1,6 +1,6 @@ import sys from _tracemalloc import * -from typing import Optional, Sequence, Union, overload +from typing import Any, Optional, Sequence, Union, overload from typing_extensions import SupportsIndex def get_object_traceback(obj: object) -> Traceback | None: ... @@ -41,6 +41,15 @@ class Frame: filename: str lineno: int def __init__(self, frame: _FrameTupleT) -> None: ... + def __lt__(self, other: Frame) -> bool: ... + if sys.version_info >= (3, 11): + def __gt__(self, other: Frame) -> bool: ... + def __ge__(self, other: Frame) -> bool: ... + def __le__(self, other: Frame) -> bool: ... + else: + def __gt__(self, other: Frame, NotImplemented: Any = ...) -> bool: ... + def __ge__(self, other: Frame, NotImplemented: Any = ...) -> bool: ... + def __le__(self, other: Frame, NotImplemented: Any = ...) -> bool: ... if sys.version_info >= (3, 9): _TraceTupleT = Union[tuple[int, int, Sequence[_FrameTupleT], Optional[int]], tuple[int, int, Sequence[_FrameTupleT]]] @@ -69,6 +78,15 @@ class Traceback(Sequence[Frame]): @overload def __getitem__(self, s: slice) -> Sequence[Frame]: ... def __len__(self) -> int: ... + def __lt__(self, other: Traceback) -> bool: ... + if sys.version_info >= (3, 11): + def __gt__(self, other: Traceback) -> bool: ... + def __ge__(self, other: Traceback) -> bool: ... + def __le__(self, other: Traceback) -> bool: ... + else: + def __gt__(self, other: Traceback, NotImplemented: Any = ...) -> bool: ... + def __ge__(self, other: Traceback, NotImplemented: Any = ...) -> bool: ... + def __le__(self, other: Traceback, NotImplemented: Any = ...) -> bool: ... class Snapshot: def __init__(self, traces: Sequence[_TraceTupleT], traceback_limit: int) -> None: ... diff --git a/stdlib/urllib/request.pyi b/stdlib/urllib/request.pyi index a69bd650c..6d59c5d5b 100644 --- a/stdlib/urllib/request.pyi +++ b/stdlib/urllib/request.pyi @@ -92,6 +92,7 @@ class BaseHandler: parent: OpenerDirector def add_parent(self, parent: OpenerDirector) -> None: ... def close(self) -> None: ... + def __lt__(self, other: object) -> bool: ... class HTTPDefaultErrorHandler(BaseHandler): def http_error_default( diff --git a/stdlib/xml/etree/ElementTree.pyi b/stdlib/xml/etree/ElementTree.pyi index fa1c01c83..4561fc82c 100644 --- a/stdlib/xml/etree/ElementTree.pyi +++ b/stdlib/xml/etree/ElementTree.pyi @@ -111,6 +111,10 @@ PI: Callable[..., Element] class QName: text: str def __init__(self, text_or_uri: str, tag: str | None = ...) -> None: ... + def __lt__(self, other: QName | str) -> bool: ... + def __le__(self, other: QName | str) -> bool: ... + def __gt__(self, other: QName | str) -> bool: ... + def __ge__(self, other: QName | str) -> bool: ... class ElementTree: def __init__(self, element: Element | None = ..., file: _File | None = ...) -> None: ...