From 52b3925b6256667d263afe2e29149d8082c4e468 Mon Sep 17 00:00:00 2001 From: David Euresti Date: Fri, 24 Feb 2017 10:45:28 -0800 Subject: [PATCH 1/5] Add stub for filecmp to 2and3 --- stdlib/2and3/filecmp.pyi | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 stdlib/2and3/filecmp.pyi diff --git a/stdlib/2and3/filecmp.pyi b/stdlib/2and3/filecmp.pyi new file mode 100644 index 000000000000..4fda37a4bad6 --- /dev/null +++ b/stdlib/2and3/filecmp.pyi @@ -0,0 +1,53 @@ +# Stubs for filecmp (Python 2/3) +import sys +from typing import AnyStr, Callable, Dict, Generic, Iterable, List, Optional, Sequence, Tuple, Union + +DEFAULT_IGNORES = ... # type: List[str] + +if sys.version_info >= (3,): + def cmp(f1:AnyStr, f2:AnyStr, shallow: bool = ...) -> bool: ... + def cmpfiles(a:AnyStr, b:AnyStr, + common:Iterable[AnyStr], + shallow: bool = ...) -> Tuple[List[AnyStr], List[AnyStr], List[AnyStr]]: ... + def clear_cache() -> None: ... +else: + # Python 2 has a default value of 1 for shallow. But it accepts a bool too. + def cmp(f1:AnyStr, f2:AnyStr, shallow: Union[int, bool] = ...) -> bool: ... + def cmpfiles(a:AnyStr, b:AnyStr, + common:Iterable[AnyStr], + shallow: Union[int, bool] = ...) -> Tuple[List[AnyStr], List[AnyStr], List[AnyStr]]: ... + +class dircmp(Generic[AnyStr]): + def __init__(self, a:AnyStr, b:AnyStr, + ignore: Optional[Sequence[AnyStr]] = ..., + hide: Optional[Sequence[AnyStr]] = ...) -> None: ... + left = ... # type: AnyStr + right = ... # type: AnyStr + hide = ... # type: Sequence[AnyStr] + ignore = ... # type: Sequence[AnyStr] + + # These are created at runtime by __getattr__ + subdirs = ... # type: Dict[AnyStr, dircmp[AnyStr]] + same_files = ... # type: List[AnyStr] + diff_files = ... # type: List[AnyStr] + funny_files = ... # type: List[AnyStr] + common_dirs = ... # type: List[AnyStr] + common_files = ... # type: List[AnyStr] + common_funny = ... # type: List[AnyStr] + common = ... # type: List[AnyStr] + left_only = ... # type: List[AnyStr] + right_only = ... # type: List[AnyStr] + left_list = ... # type: List[AnyStr] + right_list = ... # type: List[AnyStr] + + # These should probably be private. + methodmap = ... # type: Dict[str, Callable[[], None]] + def phase0(self) -> None: ... + def phase1(self) -> None: ... + def phase2(self) -> None: ... + def phase3(self) -> None: ... + def phase4(self) -> None: ... + def phase4_closure(self) -> None: ... + def report(self) -> None: ... + def report_partial_closure(self) -> None: ... + def report_full_closure(self) -> None: ... From fdfa94c60aea8e7829c270f3e1128b0168e5ecb8 Mon Sep 17 00:00:00 2001 From: David Euresti Date: Fri, 24 Feb 2017 10:54:18 -0800 Subject: [PATCH 2/5] Fix spacing --- stdlib/2and3/filecmp.pyi | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/stdlib/2and3/filecmp.pyi b/stdlib/2and3/filecmp.pyi index 4fda37a4bad6..cc37a0dc2a9d 100644 --- a/stdlib/2and3/filecmp.pyi +++ b/stdlib/2and3/filecmp.pyi @@ -5,20 +5,20 @@ from typing import AnyStr, Callable, Dict, Generic, Iterable, List, Optional, Se DEFAULT_IGNORES = ... # type: List[str] if sys.version_info >= (3,): - def cmp(f1:AnyStr, f2:AnyStr, shallow: bool = ...) -> bool: ... - def cmpfiles(a:AnyStr, b:AnyStr, - common:Iterable[AnyStr], + def cmp(f1: AnyStr, f2: AnyStr, shallow: bool = ...) -> bool: ... + def cmpfiles(a: AnyStr, b: AnyStr, + common: Iterable[AnyStr], shallow: bool = ...) -> Tuple[List[AnyStr], List[AnyStr], List[AnyStr]]: ... def clear_cache() -> None: ... else: # Python 2 has a default value of 1 for shallow. But it accepts a bool too. - def cmp(f1:AnyStr, f2:AnyStr, shallow: Union[int, bool] = ...) -> bool: ... - def cmpfiles(a:AnyStr, b:AnyStr, - common:Iterable[AnyStr], + def cmp(f1: AnyStr, f2: AnyStr, shallow: Union[int, bool] = ...) -> bool: ... + def cmpfiles(a: AnyStr, b: AnyStr, + common: Iterable[AnyStr], shallow: Union[int, bool] = ...) -> Tuple[List[AnyStr], List[AnyStr], List[AnyStr]]: ... class dircmp(Generic[AnyStr]): - def __init__(self, a:AnyStr, b:AnyStr, + def __init__(self, a: AnyStr, b: AnyStr, ignore: Optional[Sequence[AnyStr]] = ..., hide: Optional[Sequence[AnyStr]] = ...) -> None: ... left = ... # type: AnyStr From 388833253150f48ffacfc35177f82c947d5d6b69 Mon Sep 17 00:00:00 2001 From: David Euresti Date: Fri, 24 Feb 2017 10:56:42 -0800 Subject: [PATCH 3/5] Moar spacing --- stdlib/2and3/filecmp.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/2and3/filecmp.pyi b/stdlib/2and3/filecmp.pyi index cc37a0dc2a9d..5de1c4f70abf 100644 --- a/stdlib/2and3/filecmp.pyi +++ b/stdlib/2and3/filecmp.pyi @@ -28,9 +28,9 @@ class dircmp(Generic[AnyStr]): # These are created at runtime by __getattr__ subdirs = ... # type: Dict[AnyStr, dircmp[AnyStr]] - same_files = ... # type: List[AnyStr] - diff_files = ... # type: List[AnyStr] - funny_files = ... # type: List[AnyStr] + same_files = ... # type: List[AnyStr] + diff_files = ... # type: List[AnyStr] + funny_files = ... # type: List[AnyStr] common_dirs = ... # type: List[AnyStr] common_files = ... # type: List[AnyStr] common_funny = ... # type: List[AnyStr] From a897c4fef69453a4716a7809b404591d1b0940f6 Mon Sep 17 00:00:00 2001 From: David Euresti Date: Fri, 24 Feb 2017 17:30:30 -0800 Subject: [PATCH 4/5] Use _SupportsBool --- stdlib/2and3/filecmp.pyi | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/stdlib/2and3/filecmp.pyi b/stdlib/2and3/filecmp.pyi index 5de1c4f70abf..46a478855ee6 100644 --- a/stdlib/2and3/filecmp.pyi +++ b/stdlib/2and3/filecmp.pyi @@ -1,21 +1,14 @@ # Stubs for filecmp (Python 2/3) import sys -from typing import AnyStr, Callable, Dict, Generic, Iterable, List, Optional, Sequence, Tuple, Union +from typing import AnyStr, Callable, Dict, Generic, Iterable, List, Optional, Sequence, Tuple + +_SupportsBool = object DEFAULT_IGNORES = ... # type: List[str] -if sys.version_info >= (3,): - def cmp(f1: AnyStr, f2: AnyStr, shallow: bool = ...) -> bool: ... - def cmpfiles(a: AnyStr, b: AnyStr, - common: Iterable[AnyStr], - shallow: bool = ...) -> Tuple[List[AnyStr], List[AnyStr], List[AnyStr]]: ... - def clear_cache() -> None: ... -else: - # Python 2 has a default value of 1 for shallow. But it accepts a bool too. - def cmp(f1: AnyStr, f2: AnyStr, shallow: Union[int, bool] = ...) -> bool: ... - def cmpfiles(a: AnyStr, b: AnyStr, - common: Iterable[AnyStr], - shallow: Union[int, bool] = ...) -> Tuple[List[AnyStr], List[AnyStr], List[AnyStr]]: ... +def cmp(f1: AnyStr, f2: AnyStr, shallow: _SupportsBool = ...) -> bool: ... +def cmpfiles(a: AnyStr, b: AnyStr, common: Iterable[AnyStr], + shallow: _SupportsBool = ...) -> Tuple[List[AnyStr], List[AnyStr], List[AnyStr]]: ... class dircmp(Generic[AnyStr]): def __init__(self, a: AnyStr, b: AnyStr, @@ -51,3 +44,6 @@ class dircmp(Generic[AnyStr]): def report(self) -> None: ... def report_partial_closure(self) -> None: ... def report_full_closure(self) -> None: ... + +if sys.version_info >= (3,): + def clear_cache() -> None: ... From 728a89657dbdf6c641044a4affc9f4c4e5aa14b0 Mon Sep 17 00:00:00 2001 From: David Euresti Date: Thu, 2 Mar 2017 11:27:10 -0800 Subject: [PATCH 5/5] Code review --- stdlib/2and3/filecmp.pyi | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/stdlib/2and3/filecmp.pyi b/stdlib/2and3/filecmp.pyi index 46a478855ee6..cc0a621a0870 100644 --- a/stdlib/2and3/filecmp.pyi +++ b/stdlib/2and3/filecmp.pyi @@ -1,25 +1,24 @@ # Stubs for filecmp (Python 2/3) import sys -from typing import AnyStr, Callable, Dict, Generic, Iterable, List, Optional, Sequence, Tuple - -_SupportsBool = object +from typing import AnyStr, Callable, Dict, Generic, Iterable, List, Optional, Sequence, Tuple, Union, Text DEFAULT_IGNORES = ... # type: List[str] -def cmp(f1: AnyStr, f2: AnyStr, shallow: _SupportsBool = ...) -> bool: ... +def cmp(f1: Union[bytes, Text], f2: Union[bytes, Text], shallow: Union[int, bool] = ...) -> bool: ... def cmpfiles(a: AnyStr, b: AnyStr, common: Iterable[AnyStr], - shallow: _SupportsBool = ...) -> Tuple[List[AnyStr], List[AnyStr], List[AnyStr]]: ... + shallow: Union[int, bool] = ...) -> Tuple[List[AnyStr], List[AnyStr], List[AnyStr]]: ... class dircmp(Generic[AnyStr]): def __init__(self, a: AnyStr, b: AnyStr, ignore: Optional[Sequence[AnyStr]] = ..., hide: Optional[Sequence[AnyStr]] = ...) -> None: ... + left = ... # type: AnyStr right = ... # type: AnyStr hide = ... # type: Sequence[AnyStr] ignore = ... # type: Sequence[AnyStr] - # These are created at runtime by __getattr__ + # These properties are created at runtime by __getattr__ subdirs = ... # type: Dict[AnyStr, dircmp[AnyStr]] same_files = ... # type: List[AnyStr] diff_files = ... # type: List[AnyStr] @@ -33,7 +32,10 @@ class dircmp(Generic[AnyStr]): left_list = ... # type: List[AnyStr] right_list = ... # type: List[AnyStr] - # These should probably be private. + def report(self) -> None: ... + def report_partial_closure(self) -> None: ... + def report_full_closure(self) -> None: ... + methodmap = ... # type: Dict[str, Callable[[], None]] def phase0(self) -> None: ... def phase1(self) -> None: ... @@ -41,9 +43,6 @@ class dircmp(Generic[AnyStr]): def phase3(self) -> None: ... def phase4(self) -> None: ... def phase4_closure(self) -> None: ... - def report(self) -> None: ... - def report_partial_closure(self) -> None: ... - def report_full_closure(self) -> None: ... if sys.version_info >= (3,): def clear_cache() -> None: ...