From 0c2648248837c79ac9f74f6a28770ffdbb553515 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Thu, 23 Jun 2016 17:35:25 -0700 Subject: [PATCH] difflib functions return Iterators, not Iterables (#310) These functions all use yield. It's valid to call the next method on the return value, which is not true of Iterables. --- stdlib/2.7/difflib.pyi | 13 +++++++------ stdlib/3/difflib.pyi | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/stdlib/2.7/difflib.pyi b/stdlib/2.7/difflib.pyi index eaf2b5dbb..5580ce622 100644 --- a/stdlib/2.7/difflib.pyi +++ b/stdlib/2.7/difflib.pyi @@ -5,7 +5,8 @@ # TODO: Support unicode? from typing import ( - TypeVar, Callable, Iterable, List, NamedTuple, Sequence, Tuple, Generic + TypeVar, Callable, Iterable, Iterator, List, NamedTuple, Sequence, Tuple, + Generic ) _T = TypeVar('_T') @@ -33,20 +34,20 @@ def get_close_matches(word: Sequence[_T], possibilities: List[Sequence[_T]], class Differ: def __init__(self, linejunk: Callable[[str], bool] = ..., charjunk: Callable[[str], bool] = ...) -> None: ... - def compare(self, a: Sequence[str], b: Sequence[str]) -> Iterable[str]: ... + def compare(self, a: Sequence[str], b: Sequence[str]) -> Iterator[str]: ... def IS_LINE_JUNK(str) -> bool: ... def IS_CHARACTER_JUNK(str) -> bool: ... def unified_diff(a: Sequence[str], b: Sequence[str], fromfile: str = ..., tofile: str = ..., fromfiledate: str = ..., tofiledate: str = ..., - n: int = ..., lineterm: str = ...) -> Iterable[str]: ... + n: int = ..., lineterm: str = ...) -> Iterator[str]: ... def context_diff(a: Sequence[str], b: Sequence[str], fromfile: str=..., tofile: str = ..., fromfiledate: str = ..., tofiledate: str = ..., - n: int = ..., lineterm: str = ...) -> Iterable[str]: ... + n: int = ..., lineterm: str = ...) -> Iterator[str]: ... def ndiff(a: Sequence[str], b: Sequence[str], linejunk: Callable[[str], bool] = ..., charjunk: Callable[[str], bool] = ... - ) -> Iterable[str]: ... + ) -> Iterator[str]: ... class HtmlDiff(object): def __init__(self, tabsize: int = ..., wrapcolumn: int = ..., @@ -60,4 +61,4 @@ class HtmlDiff(object): fromdesc: str = ..., todesc: str = ..., context: bool = ..., numlines: int = ...) -> str: ... -def restore(delta: Iterable[str], which: int) -> Iterable[int]: ... +def restore(delta: Iterable[str], which: int) -> Iterator[int]: ... diff --git a/stdlib/3/difflib.pyi b/stdlib/3/difflib.pyi index 98da32771..a05db8d6e 100644 --- a/stdlib/3/difflib.pyi +++ b/stdlib/3/difflib.pyi @@ -3,7 +3,8 @@ # Based on https://docs.python.org/3.2/library/difflib.html from typing import ( - TypeVar, Callable, Iterable, List, NamedTuple, Sequence, Tuple, Generic + TypeVar, Callable, Iterable, Iterator, List, NamedTuple, Sequence, Tuple, + Generic ) _T = TypeVar('_T') @@ -31,20 +32,20 @@ def get_close_matches(word: Sequence[_T], possibilities: List[Sequence[_T]], class Differ: def __init__(self, linejunk: Callable[[str], bool] = ..., charjunk: Callable[[str], bool] = ...) -> None: ... - def compare(self, a: Sequence[str], b: Sequence[str]) -> Iterable[str]: ... + def compare(self, a: Sequence[str], b: Sequence[str]) -> Iterator[str]: ... def IS_LINE_JUNK(str) -> bool: ... def IS_CHARACTER_JUNK(str) -> bool: ... def unified_diff(a: Sequence[str], b: Sequence[str], fromfile: str = ..., tofile: str = ..., fromfiledate: str = ..., tofiledate: str = ..., - n: int = ..., lineterm: str = ...) -> Iterable[str]: ... + n: int = ..., lineterm: str = ...) -> Iterator[str]: ... def context_diff(a: Sequence[str], b: Sequence[str], fromfile: str=..., tofile: str = ..., fromfiledate: str = ..., tofiledate: str = ..., - n: int = ..., lineterm: str = ...) -> Iterable[str]: ... + n: int = ..., lineterm: str = ...) -> Iterator[str]: ... def ndiff(a: Sequence[str], b: Sequence[str], linejunk: Callable[[str], bool] = ..., charjunk: Callable[[str], bool] = ... - ) -> Iterable[str]: ... + ) -> Iterator[str]: ... class HtmlDiff(object): def __init__(self, tabsize: int = ..., wrapcolumn: int = ..., @@ -58,4 +59,4 @@ class HtmlDiff(object): fromdesc: str = ..., todesc: str = ..., context: bool = ..., numlines: int = ...) -> str: ... -def restore(delta: Iterable[str], which: int) -> Iterable[int]: ... +def restore(delta: Iterable[str], which: int) -> Iterator[int]: ...