1import sys
2from typing import (
3    Any,
4    AnyStr,
5    Callable,
6    Generic,
7    Iterable,
8    Iterator,
9    List,
10    NamedTuple,
11    Optional,
12    Sequence,
13    Tuple,
14    TypeVar,
15    Union,
16    overload,
17)
18
19if sys.version_info >= (3, 9):
20    from types import GenericAlias
21
22_T = TypeVar("_T")
23_JunkCallback = Union[Callable[[str], bool], Callable[[str], bool]]
24
25class Match(NamedTuple):
26    a: int
27    b: int
28    size: int
29
30class SequenceMatcher(Generic[_T]):
31    def __init__(
32        self, isjunk: Optional[Callable[[_T], bool]] = ..., a: Sequence[_T] = ..., b: Sequence[_T] = ..., autojunk: bool = ...
33    ) -> None: ...
34    def set_seqs(self, a: Sequence[_T], b: Sequence[_T]) -> None: ...
35    def set_seq1(self, a: Sequence[_T]) -> None: ...
36    def set_seq2(self, b: Sequence[_T]) -> None: ...
37    if sys.version_info >= (3, 9):
38        def find_longest_match(
39            self, alo: int = ..., ahi: Optional[int] = ..., blo: int = ..., bhi: Optional[int] = ...
40        ) -> Match: ...
41    else:
42        def find_longest_match(self, alo: int, ahi: int, blo: int, bhi: int) -> Match: ...
43    def get_matching_blocks(self) -> List[Match]: ...
44    def get_opcodes(self) -> List[Tuple[str, int, int, int, int]]: ...
45    def get_grouped_opcodes(self, n: int = ...) -> Iterable[List[Tuple[str, int, int, int, int]]]: ...
46    def ratio(self) -> float: ...
47    def quick_ratio(self) -> float: ...
48    def real_quick_ratio(self) -> float: ...
49    if sys.version_info >= (3, 9):
50        def __class_getitem__(cls, item: Any) -> GenericAlias: ...
51
52# mypy thinks the signatures of the overloads overlap, but the types still work fine
53@overload
54def get_close_matches(  # type: ignore
55    word: AnyStr, possibilities: Iterable[AnyStr], n: int = ..., cutoff: float = ...
56) -> List[AnyStr]: ...
57@overload
58def get_close_matches(
59    word: Sequence[_T], possibilities: Iterable[Sequence[_T]], n: int = ..., cutoff: float = ...
60) -> List[Sequence[_T]]: ...
61
62class Differ:
63    def __init__(self, linejunk: Optional[_JunkCallback] = ..., charjunk: Optional[_JunkCallback] = ...) -> None: ...
64    def compare(self, a: Sequence[str], b: Sequence[str]) -> Iterator[str]: ...
65
66def IS_LINE_JUNK(line: str, pat: Any = ...) -> bool: ...  # pat is undocumented
67def IS_CHARACTER_JUNK(ch: str, ws: str = ...) -> bool: ...  # ws is undocumented
68def unified_diff(
69    a: Sequence[str],
70    b: Sequence[str],
71    fromfile: str = ...,
72    tofile: str = ...,
73    fromfiledate: str = ...,
74    tofiledate: str = ...,
75    n: int = ...,
76    lineterm: str = ...,
77) -> Iterator[str]: ...
78def context_diff(
79    a: Sequence[str],
80    b: Sequence[str],
81    fromfile: str = ...,
82    tofile: str = ...,
83    fromfiledate: str = ...,
84    tofiledate: str = ...,
85    n: int = ...,
86    lineterm: str = ...,
87) -> Iterator[str]: ...
88def ndiff(
89    a: Sequence[str], b: Sequence[str], linejunk: Optional[_JunkCallback] = ..., charjunk: Optional[_JunkCallback] = ...
90) -> Iterator[str]: ...
91
92class HtmlDiff(object):
93    def __init__(
94        self,
95        tabsize: int = ...,
96        wrapcolumn: Optional[int] = ...,
97        linejunk: Optional[_JunkCallback] = ...,
98        charjunk: Optional[_JunkCallback] = ...,
99    ) -> None: ...
100    def make_file(
101        self,
102        fromlines: Sequence[str],
103        tolines: Sequence[str],
104        fromdesc: str = ...,
105        todesc: str = ...,
106        context: bool = ...,
107        numlines: int = ...,
108        *,
109        charset: str = ...,
110    ) -> str: ...
111    def make_table(
112        self,
113        fromlines: Sequence[str],
114        tolines: Sequence[str],
115        fromdesc: str = ...,
116        todesc: str = ...,
117        context: bool = ...,
118        numlines: int = ...,
119    ) -> str: ...
120
121def restore(delta: Iterable[str], which: int) -> Iterator[str]: ...
122def diff_bytes(
123    dfunc: Callable[[Sequence[str], Sequence[str], str, str, str, str, int, str], Iterator[str]],
124    a: Sequence[bytes],
125    b: Sequence[bytes],
126    fromfile: bytes = ...,
127    tofile: bytes = ...,
128    fromfiledate: bytes = ...,
129    tofiledate: bytes = ...,
130    n: int = ...,
131    lineterm: bytes = ...,
132) -> Iterator[bytes]: ...
133