Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion stdlib/2and3/difflib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

# TODO: Support unicode in Python 2?

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

_T = TypeVar('_T')

Match = NamedTuple('Match', [
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose you could use the PEP 526 syntax too, but I'll merge as-is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't work actually, mypy only lets you do that in 3.6.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But IIUC stubs are always processed in 3.6 mode. (Maybe you can try this out?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried, in 3.5 mode mypy gives

stdlib/2and3/difflib.pyi:19: error: NamedTuple class syntax is only supported in Python 3.6

Somebody (David I think?) explained that while syntactic 3.6 features work in all stubs, language-level 3.6 features don't. I'm not sure that distinction really makes sense to me, but I guess what it means concretely is that typed_ast processes stubs in 3.6 mode, but mypy's semantic analyzer uses 2.7 mode if mypy is in 2.7 mode, and the semantic analyzer is the place that rejects NamedTuple class syntax.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That must be it. :-(

('a', int),
('b', int),
('size', int),
])

class SequenceMatcher(Generic[_T]):
def __init__(self, isjunk: Optional[Callable[[_T], bool]] = ...,
a: Sequence[_T] = ..., b: Sequence[_T] = ...,
Expand All @@ -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]]: ...
Expand Down Expand Up @@ -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]: ...