Make functools.cmp_to_key more realistic (#458)

The documentation[1] says:

    A comparison function is any callable that accept two arguments,
    compares them, and returns a negative number for less-than, zero for
    equality, or a positive number for greater-than.

This doesn't seem possible with the comparison function defined as
returning bool.

[1] https://docs.python.org/3.6/library/functools.html#functools.cmp_to_key
This commit is contained in:
Jakub Stasiak
2016-08-10 21:12:52 +02:00
committed by Guido van Rossum
parent ebdf9d68b2
commit 0edb87fc6b
2 changed files with 2 additions and 2 deletions

View File

@@ -24,7 +24,7 @@ def update_wrapper(wrapper: _AnyCallable, wrapped: _AnyCallable, assigned: Seque
updated: Sequence[str] = ...) -> None: ...
def wraps(wrapped: _AnyCallable, assigned: Sequence[str] = ..., updated: Sequence[str] = ...) -> Callable[[_AnyCallable], _AnyCallable]: ...
def total_ordering(cls: type) -> type: ...
def cmp_to_key(mycmp: Callable[[_T, _T], bool]) -> Callable[[_T], Any]: ...
def cmp_to_key(mycmp: Callable[[_T, _T], int]) -> Callable[[_T], Any]: ...
class partial(Generic[_T]):
func = ... # Callable[..., _T]

View File

@@ -40,7 +40,7 @@ def update_wrapper(wrapper: _AnyCallable, wrapped: _AnyCallable, assigned: Seque
updated: Sequence[str] = ...) -> None: ...
def wraps(wrapped: _AnyCallable, assigned: Sequence[str] = ..., updated: Sequence[str] = ...) -> Callable[[_AnyCallable], _AnyCallable]: ...
def total_ordering(cls: type) -> type: ...
def cmp_to_key(mycmp: Callable[[_T, _T], bool]) -> Callable[[_T], Any]: ...
def cmp_to_key(mycmp: Callable[[_T, _T], int]) -> Callable[[_T], Any]: ...
class partial(Generic[_T]):
func = ... # Callable[..., _T]