From 2f82c44af0f28d5eea405feb5166d5e329722ec4 Mon Sep 17 00:00:00 2001 From: Luciano Ramalho Date: Tue, 26 May 2020 01:48:25 -0300 Subject: [PATCH] Hashable bounded typevar for mode, multimode (#4084) Fixes #4057 --- stdlib/3/statistics.pyi | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/stdlib/3/statistics.pyi b/stdlib/3/statistics.pyi index bd30885c6..966b8f3cb 100644 --- a/stdlib/3/statistics.pyi +++ b/stdlib/3/statistics.pyi @@ -3,7 +3,7 @@ from decimal import Decimal from fractions import Fraction import sys -from typing import Any, Iterable, List, Optional, SupportsFloat, Type, TypeVar, Union, Protocol +from typing import Any, Iterable, List, Optional, SupportsFloat, Type, TypeVar, Union, Protocol, Hashable _T = TypeVar("_T") # Most functions in this module accept homogeneous collections of one of these types @@ -14,6 +14,9 @@ class _Sortable(Protocol): def __lt__(self, other) -> bool: ... _SortableT = TypeVar("_SortableT", bound=_Sortable) +# Used in mode, multimode +_HashableT = TypeVar("_HashableT", bound=Hashable) + class StatisticsError(ValueError): ... if sys.version_info >= (3, 8): @@ -26,9 +29,9 @@ def median(data: Iterable[_Number]) -> _Number: ... def median_low(data: Iterable[_SortableT]) -> _SortableT: ... def median_high(data: Iterable[_SortableT]) -> _SortableT: ... def median_grouped(data: Iterable[_Number], interval: _Number = ...) -> _Number: ... -def mode(data: Iterable[_Number]) -> _Number: ... +def mode(data: Iterable[_HashableT]) -> _HashableT: ... if sys.version_info >= (3, 8): - def multimode(data: Iterable[_T]) -> List[_T]: ... + def multimode(data: Iterable[_HashableT]) -> List[_HashableT]: ... def pstdev(data: Iterable[_Number], mu: Optional[_Number] = ...) -> _Number: ... def pvariance(data: Iterable[_Number], mu: Optional[_Number] = ...) -> _Number: ... if sys.version_info >= (3, 8):