From e613018480dadf2b9590250ebbcd436b84e2ebb4 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 4 Apr 2020 21:48:17 -0700 Subject: [PATCH 1/4] add overload to difflib.get_close_matches Fixes #3906. Fixes #2067. --- stdlib/2and3/difflib.pyi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stdlib/2and3/difflib.pyi b/stdlib/2and3/difflib.pyi index 5b285e070402..db8d09709264 100644 --- a/stdlib/2and3/difflib.pyi +++ b/stdlib/2and3/difflib.pyi @@ -38,6 +38,10 @@ class SequenceMatcher(Generic[_T]): def quick_ratio(self) -> float: ... def real_quick_ratio(self) -> float: ... +@overload +def get_close_matches(word: str, possibilities: Iterable[str], + n: int = ..., cutoff: float = ...) -> List[str]: ... +@overload def get_close_matches(word: Sequence[_T], possibilities: Iterable[Sequence[_T]], n: int = ..., cutoff: float = ...) -> List[Sequence[_T]]: ... From 7ea89efdacd0b0eceae99083e91594356148d722 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 4 Apr 2020 22:11:41 -0700 Subject: [PATCH 2/4] use AnyStr for the overload --- stdlib/2and3/difflib.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2and3/difflib.pyi b/stdlib/2and3/difflib.pyi index db8d09709264..b33bfac4b703 100644 --- a/stdlib/2and3/difflib.pyi +++ b/stdlib/2and3/difflib.pyi @@ -39,8 +39,8 @@ class SequenceMatcher(Generic[_T]): def real_quick_ratio(self) -> float: ... @overload -def get_close_matches(word: str, possibilities: Iterable[str], - n: int = ..., cutoff: float = ...) -> List[str]: ... +def get_close_matches(word: AnyStr, possibilities: Iterable[AnyStr], + n: int = ..., cutoff: float = ...) -> List[AnyStr]: ... @overload def get_close_matches(word: Sequence[_T], possibilities: Iterable[Sequence[_T]], n: int = ..., cutoff: float = ...) -> List[Sequence[_T]]: ... From e3196d3da4dfbb38f1b199f16eb542f1e6bca05a Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 4 Apr 2020 22:13:02 -0700 Subject: [PATCH 3/4] import overload --- stdlib/2and3/difflib.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/2and3/difflib.pyi b/stdlib/2and3/difflib.pyi index b33bfac4b703..74743f65c825 100644 --- a/stdlib/2and3/difflib.pyi +++ b/stdlib/2and3/difflib.pyi @@ -3,7 +3,7 @@ import sys from typing import ( Any, TypeVar, Callable, Iterable, Iterator, List, NamedTuple, Sequence, Tuple, - Generic, Optional, Text, Union, AnyStr + Generic, Optional, Text, Union, AnyStr, overload ) _T = TypeVar('_T') From 5ac39420b36ebd4254dc9b4516d5e741a31ba744 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 4 Apr 2020 22:49:27 -0700 Subject: [PATCH 4/4] add type ignore --- stdlib/2and3/difflib.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/2and3/difflib.pyi b/stdlib/2and3/difflib.pyi index 74743f65c825..4804ef820fec 100644 --- a/stdlib/2and3/difflib.pyi +++ b/stdlib/2and3/difflib.pyi @@ -38,8 +38,9 @@ class SequenceMatcher(Generic[_T]): def quick_ratio(self) -> float: ... def real_quick_ratio(self) -> float: ... +# mypy thinks the signatures of the overloads overlap, but the types still work fine @overload -def get_close_matches(word: AnyStr, possibilities: Iterable[AnyStr], +def get_close_matches(word: AnyStr, possibilities: Iterable[AnyStr], # type: ignore n: int = ..., cutoff: float = ...) -> List[AnyStr]: ... @overload def get_close_matches(word: Sequence[_T], possibilities: Iterable[Sequence[_T]],