From a6e369906d013c76d535d9a05466d22c54c832a7 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 21 Nov 2021 13:28:46 +0100 Subject: [PATCH] max() uses SupportsGreaterThanT (#6342) Add SupportsGreaterThan and SupportsGreaterThanT Closes: #6336 Co-authored-by: Jelle Zijlstra --- stdlib/_typeshed/__init__.pyi | 5 +++++ stdlib/builtins.pyi | 16 +++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index 6dd0b38c2..8c0005294 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -40,6 +40,11 @@ class SupportsLessThan(Protocol): SupportsLessThanT = TypeVar("SupportsLessThanT", bound=SupportsLessThan) # noqa: Y001 +class SupportsGreaterThan(Protocol): + def __gt__(self, __other: Any) -> bool: ... + +SupportsGreaterThanT = TypeVar("SupportsGreaterThanT", bound=SupportsGreaterThan) # noqa: Y001 + class SupportsDivMod(Protocol[_T_contra, _T_co]): def __divmod__(self, __other: _T_contra) -> _T_co: ... diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 0f201f9f2..388ce3380 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -13,6 +13,8 @@ from _typeshed import ( StrOrBytesPath, SupportsAnext, SupportsDivMod, + SupportsGreaterThan, + SupportsGreaterThanT, SupportsKeysAndGetItem, SupportsLenAndGetItem, SupportsLessThan, @@ -1139,18 +1141,18 @@ class map(Iterator[_S], Generic[_S]): @overload def max( - __arg1: SupportsLessThanT, __arg2: SupportsLessThanT, *_args: SupportsLessThanT, key: None = ... -) -> SupportsLessThanT: ... + __arg1: SupportsGreaterThanT, __arg2: SupportsGreaterThanT, *_args: SupportsGreaterThanT, key: None = ... +) -> SupportsGreaterThanT: ... @overload -def max(__arg1: _T, __arg2: _T, *_args: _T, key: Callable[[_T], SupportsLessThan]) -> _T: ... +def max(__arg1: _T, __arg2: _T, *_args: _T, key: Callable[[_T], SupportsGreaterThan]) -> _T: ... @overload -def max(__iterable: Iterable[SupportsLessThanT], *, key: None = ...) -> SupportsLessThanT: ... +def max(__iterable: Iterable[SupportsGreaterThanT], *, key: None = ...) -> SupportsGreaterThanT: ... @overload -def max(__iterable: Iterable[_T], *, key: Callable[[_T], SupportsLessThan]) -> _T: ... +def max(__iterable: Iterable[_T], *, key: Callable[[_T], SupportsGreaterThan]) -> _T: ... @overload -def max(__iterable: Iterable[SupportsLessThanT], *, key: None = ..., default: _T) -> SupportsLessThanT | _T: ... +def max(__iterable: Iterable[SupportsGreaterThanT], *, key: None = ..., default: _T) -> SupportsGreaterThanT | _T: ... @overload -def max(__iterable: Iterable[_T1], *, key: Callable[[_T1], SupportsLessThan], default: _T2) -> _T1 | _T2: ... +def max(__iterable: Iterable[_T1], *, key: Callable[[_T1], SupportsGreaterThan], default: _T2) -> _T1 | _T2: ... @overload def min( __arg1: SupportsLessThanT, __arg2: SupportsLessThanT, *_args: SupportsLessThanT, key: None = ...