make difflib use str on 3 and AnyStr on 2 (#2160)

This commit is contained in:
Michael J. Sullivan
2018-05-24 13:53:42 -07:00
committed by GitHub
parent db1316d26b
commit c55cf13d8e

View File

@@ -3,10 +3,17 @@
import sys
from typing import (
TypeVar, Callable, Iterable, Iterator, List, NamedTuple, Sequence, Tuple,
Generic, Optional, Text, Union
Generic, Optional, Text, Union, AnyStr
)
_T = TypeVar('_T')
if sys.version_info >= (3,):
_StrType = Text
else:
# Aliases can't point to type vars, so we need to redeclare AnyStr
_StrType = TypeVar('_StrType', str, bytes)
_JunkCallback = Union[Callable[[Text], bool], Callable[[str], bool]]
Match = NamedTuple('Match', [
@@ -37,34 +44,34 @@ def get_close_matches(word: Sequence[_T], possibilities: Iterable[Sequence[_T]],
class Differ:
def __init__(self, linejunk: _JunkCallback = ..., charjunk: _JunkCallback = ...) -> None: ...
def compare(self, a: Sequence[Text], b: Sequence[Text]) -> Iterator[Text]: ...
def compare(self, a: Sequence[_StrType], b: Sequence[_StrType]) -> Iterator[_StrType]: ...
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],
def IS_LINE_JUNK(line: _StrType) -> bool: ...
def IS_CHARACTER_JUNK(line: _StrType) -> bool: ...
def unified_diff(a: Sequence[_StrType], b: Sequence[_StrType], fromfile: _StrType = ...,
tofile: _StrType = ..., fromfiledate: _StrType = ..., tofiledate: _StrType = ...,
n: int = ..., lineterm: _StrType = ...) -> Iterator[_StrType]: ...
def context_diff(a: Sequence[_StrType], b: Sequence[_StrType], fromfile: _StrType =...,
tofile: _StrType = ..., fromfiledate: _StrType = ..., tofiledate: _StrType = ...,
n: int = ..., lineterm: _StrType = ...) -> Iterator[_StrType]: ...
def ndiff(a: Sequence[_StrType], b: Sequence[_StrType],
linejunk: _JunkCallback = ...,
charjunk: _JunkCallback = ...
) -> Iterator[Text]: ...
) -> Iterator[_StrType]: ...
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 make_file(self, fromlines: Sequence[_StrType], tolines: Sequence[_StrType],
fromdesc: _StrType = ..., todesc: _StrType = ..., context: bool = ...,
numlines: int = ...) -> _StrType: ...
def make_table(self, fromlines: Sequence[_StrType], tolines: Sequence[_StrType],
fromdesc: _StrType = ..., todesc: _StrType = ..., context: bool = ...,
numlines: int = ...) -> _StrType: ...
def restore(delta: Iterable[Text], which: int) -> Iterator[Text]: ...
def restore(delta: Iterable[_StrType], which: int) -> Iterator[_StrType]: ...
if sys.version_info >= (3, 5):
def diff_bytes(