From 48c922e54a27e5c96c679448340792d767404770 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sat, 29 Aug 2020 17:25:11 -0700 Subject: [PATCH] functools: use protocol for cmp_to_key return type (#4492) Co-authored-by: hauntsaninja <> --- stdlib/3/functools.pyi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stdlib/3/functools.pyi b/stdlib/3/functools.pyi index 3a58287fd..29c517570 100644 --- a/stdlib/3/functools.pyi +++ b/stdlib/3/functools.pyi @@ -9,6 +9,7 @@ from typing import ( Mapping, NamedTuple, Optional, + Protocol, Sequence, Tuple, Type, @@ -57,7 +58,11 @@ def wraps( wrapped: _AnyCallable, assigned: Sequence[str] = ..., updated: Sequence[str] = ... ) -> Callable[[_AnyCallable], _AnyCallable]: ... def total_ordering(cls: Type[_T]) -> Type[_T]: ... -def cmp_to_key(mycmp: Callable[[_T, _T], int]) -> Callable[[_T], Any]: ... + +class _SupportsLessThan(Protocol): + def __lt__(self, __other: Any) -> bool: ... + +def cmp_to_key(mycmp: Callable[[_T, _T], int]) -> Callable[[_T], _SupportsLessThan]: ... class partial(Generic[_T]): func: Callable[..., _T]