# Based on https://docs.python.org/2.7/library/difflib.html and https://docs.python.org/3.2/library/difflib.html

import sys
from typing import (
    TypeVar, Callable, Iterable, Iterator, List, NamedTuple, Sequence, Tuple,
    Generic, Optional, Text, Union
)

_T = TypeVar('_T')
_JunkCallback = Union[Callable[[Text], bool], Callable[[str], bool]]

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] = ...,
                 autojunk: bool = ...) -> None: ...
    def set_seqs(self, a: Sequence[_T], b: Sequence[_T]) -> None: ...
    def set_seq1(self, a: Sequence[_T]) -> None: ...
    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[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]]: ...
    def ratio(self) -> float: ...
    def quick_ratio(self) -> float: ...
    def real_quick_ratio(self) -> float: ...

def get_close_matches(word: Sequence[_T], possibilities: Iterable[Sequence[_T]],
                      n: int = ..., cutoff: float = ...) -> List[Sequence[_T]]: ...

class Differ:
    def __init__(self, linejunk: _JunkCallback = ..., charjunk: _JunkCallback = ...) -> None: ...
    def compare(self, a: Sequence[Text], b: Sequence[Text]) -> Iterator[Text]: ...

def IS_LINE_JUNK(line: Text) -> bool: ...
def IS_CHARACTER_JUNK(line: Text) -> bool: ...
def unified_diff(a: Sequence[Text], b: Sequence[Text], fromfile: Text = ...,
                 tofile: Text = ..., fromfiledate: Text = ..., tofiledate: Text = ...,
                 n: int = ..., lineterm: Text = ...) -> Iterator[Text]: ...
def context_diff(a: Sequence[Text], b: Sequence[Text], fromfile: Text=...,
                 tofile: Text = ..., fromfiledate: Text = ..., tofiledate: Text = ...,
                 n: int = ..., lineterm: Text = ...) -> Iterator[Text]: ...
def ndiff(a: Sequence[Text], b: Sequence[Text],
          linejunk: _JunkCallback = ...,
          charjunk: _JunkCallback = ...
          ) -> Iterator[Text]: ...

class HtmlDiff(object):
    def __init__(self, tabsize: int = ..., wrapcolumn: int = ...,
                 linejunk: _JunkCallback = ...,
                 charjunk: _JunkCallback = ...
                 ) -> None: ...
    def make_file(self, fromlines: Sequence[Text], tolines: Sequence[Text],
                  fromdesc: Text = ..., todesc: Text = ..., context: bool = ...,
                  numlines: int = ...) -> Text: ...
    def make_table(self, fromlines: Sequence[Text], tolines: Sequence[Text],
                   fromdesc: Text = ..., todesc: Text = ..., context: bool = ...,
                   numlines: int = ...) -> Text: ...

def restore(delta: Iterable[Text], which: int) -> Iterator[Text]: ...

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]: ...
