_typeshed: add SupportsLessThan, SupportsLessThanT (#4711)

And use it everywhere. Note there seemed to be a discrepancy between
heapq in Python 2 and 3, so I changed that. It should probably be more
widely used within heapq, but leaving that out of scope for this PR.

Co-authored-by: hauntsaninja <>
This commit is contained in:
Shantanu
2020-10-25 15:04:43 -07:00
committed by GitHub
parent 8d4a4f9e74
commit 1dd1b701c9
8 changed files with 37 additions and 51 deletions

View File

@@ -1,4 +1,5 @@
import sys
from _typeshed import SupportsLessThanT
from decimal import Decimal
from fractions import Fraction
from typing import Any, Hashable, Iterable, List, Optional, Protocol, SupportsFloat, Type, TypeVar, Union
@@ -7,12 +8,6 @@ _T = TypeVar("_T")
# Most functions in this module accept homogeneous collections of one of these types
_Number = TypeVar("_Number", float, Decimal, Fraction)
# Used in median_high, median_low
class _Sortable(Protocol):
def __lt__(self, other: Any) -> bool: ...
_SortableT = TypeVar("_SortableT", bound=_Sortable)
# Used in mode, multimode
_HashableT = TypeVar("_HashableT", bound=Hashable)
@@ -28,8 +23,8 @@ if sys.version_info >= (3, 6):
def harmonic_mean(data: Iterable[_Number]) -> _Number: ...
def median(data: Iterable[_Number]) -> _Number: ...
def median_low(data: Iterable[_SortableT]) -> _SortableT: ...
def median_high(data: Iterable[_SortableT]) -> _SortableT: ...
def median_low(data: Iterable[SupportsLessThanT]) -> SupportsLessThanT: ...
def median_high(data: Iterable[SupportsLessThanT]) -> SupportsLessThanT: ...
def median_grouped(data: Iterable[_Number], interval: _Number = ...) -> _Number: ...
def mode(data: Iterable[_HashableT]) -> _HashableT: ...