From 9bbcb0822da72222b892debb9c3fdef0eeb4661a Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 26 May 2017 09:32:34 -0700 Subject: [PATCH] add difflib.diff_bytes and difflib.Match (#1336) --- stdlib/2and3/difflib.pyi | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/stdlib/2and3/difflib.pyi b/stdlib/2and3/difflib.pyi index cae69775c..4701e32a2 100644 --- a/stdlib/2and3/difflib.pyi +++ b/stdlib/2and3/difflib.pyi @@ -2,6 +2,7 @@ # TODO: Support unicode in Python 2? +import sys from typing import ( TypeVar, Callable, Iterable, Iterator, List, NamedTuple, Sequence, Tuple, Generic, Optional @@ -9,6 +10,12 @@ from typing import ( _T = TypeVar('_T') +Match = NamedTuple('Match', [ + ('a', int), + ('b', int), + ('size', int), +]) + class SequenceMatcher(Generic[_T]): def __init__(self, isjunk: Optional[Callable[[_T], bool]] = ..., a: Sequence[_T] = ..., b: Sequence[_T] = ..., @@ -18,7 +25,7 @@ class SequenceMatcher(Generic[_T]): def set_seq2(self, b: Sequence[_T]) -> None: ... def find_longest_match(self, alo: int, ahi: int, blo: int, bhi: int) -> Tuple[int, int, int]: ... - def get_matching_blocks(self) -> List[Tuple[int, int, int]]: ... + def get_matching_blocks(self) -> List[Match]: ... def get_opcodes(self) -> List[Tuple[str, int, int, int, int]]: ... def get_grouped_opcodes(self, n: int = ... ) -> Iterable[Tuple[str, int, int, int, int]]: ... @@ -60,3 +67,16 @@ class HtmlDiff(object): numlines: int = ...) -> str: ... def restore(delta: Iterable[str], which: int) -> Iterator[int]: ... + +if sys.version_info >= (3, 5): + def diff_bytes( + dfunc: Callable[[Sequence[str], Sequence[str], str, str, str, str, int, str], Iterator[str]], + a: Sequence[bytes], + b: Sequence[bytes], + fromfile: bytes = ..., + tofile: bytes = ..., + fromfiledate: bytes = ..., + tofiledate: bytes = ..., + n: int = ..., + lineterm: bytes = ... + ) -> Iterator[bytes]: ...