Skip to content

Commit 26360e8

Browse files
eurestiJelleZijlstra
authored andcommitted
Merge stdlib/{2,3}/os/path.pyi (#1150)
* Merge stdlib/{2,3}/os/path.pyi To be renamed into stdlib/2and3/os/path.pyi later. Also fixes #50 * CR fixes
1 parent aa0d0d1 commit 26360e8

File tree

2 files changed

+61
-35
lines changed

2 files changed

+61
-35
lines changed

stdlib/2/os/path.pyi

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33

44
# based on http://docs.python.org/3.2/library/os.path.html
55
# adapted for 2.7 by Michal Pokorny
6+
import sys
7+
from typing import (
8+
overload, List, Any, AnyStr, Sequence, Tuple, BinaryIO, TextIO,
9+
TypeVar, Union, Text, Callable
10+
)
611

7-
from typing import overload, List, Any, Tuple, BinaryIO, TextIO, TypeVar, Callable, AnyStr
12+
_T = TypeVar('_T')
13+
_PathType = Union[bytes, Text]
814

915
# ----- os.path variables -----
1016
supports_unicode_filenames = False
@@ -22,25 +28,32 @@ devnull = ... # type: str
2228
def abspath(path: AnyStr) -> AnyStr: ...
2329
def basename(path: AnyStr) -> AnyStr: ...
2430

25-
def commonprefix(list: List[AnyStr]) -> AnyStr: ...
31+
if sys.version_info >= (3, 5):
32+
def commonpath(paths: Sequence[AnyStr]) -> AnyStr: ...
33+
34+
# NOTE: Empty lists results in '' (str) regardless of contained type.
35+
# Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes
36+
# So, fall back to Any
37+
def commonprefix(list: Sequence[AnyStr]) -> Any: ...
38+
2639
def dirname(path: AnyStr) -> AnyStr: ...
27-
def exists(path: unicode) -> bool: ...
28-
def lexists(path: unicode) -> bool: ...
40+
def exists(path: _PathType) -> bool: ...
41+
def lexists(path: _PathType) -> bool: ...
2942
def expanduser(path: AnyStr) -> AnyStr: ...
3043
def expandvars(path: AnyStr) -> AnyStr: ...
3144

3245
# These return float if os.stat_float_times() == True,
3346
# but int is a subclass of float.
34-
def getatime(path: unicode) -> float: ...
35-
def getmtime(path: unicode) -> float: ...
36-
def getctime(path: unicode) -> float: ...
47+
def getatime(path: _PathType) -> float: ...
48+
def getmtime(path: _PathType) -> float: ...
49+
def getctime(path: _PathType) -> float: ...
3750

38-
def getsize(path: unicode) -> int: ...
39-
def isabs(path: unicode) -> bool: ...
40-
def isfile(path: unicode) -> bool: ...
41-
def isdir(path: unicode) -> bool: ...
42-
def islink(path: unicode) -> bool: ...
43-
def ismount(path: unicode) -> bool: ...
51+
def getsize(path: _PathType) -> int: ...
52+
def isabs(path: _PathType) -> bool: ...
53+
def isfile(path: _PathType) -> bool: ...
54+
def isdir(path: _PathType) -> bool: ...
55+
def islink(path: _PathType) -> bool: ...
56+
def ismount(path: _PathType) -> bool: ...
4457

4558
def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ...
4659

@@ -49,7 +62,7 @@ def normpath(path: AnyStr) -> AnyStr: ...
4962
def realpath(path: AnyStr) -> AnyStr: ...
5063
def relpath(path: AnyStr, start: AnyStr = ...) -> AnyStr: ...
5164

52-
def samefile(path1: unicode, path2: unicode) -> bool: ...
65+
def samefile(path1: _PathType, path2: _PathType) -> bool: ...
5366
def sameopenfile(fp1: int, fp2: int) -> bool: ...
5467
# TODO
5568
# def samestat(stat1: stat_result,
@@ -61,5 +74,5 @@ def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
6174

6275
def splitunc(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # Windows only, deprecated
6376

64-
_T = TypeVar('_T')
65-
def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ...
77+
if sys.version_info < (3,):
78+
def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ...

stdlib/3/os/path.pyi

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
# Ron Murawski <[email protected]>
33

44
# based on http://docs.python.org/3.2/library/os.path.html
5-
5+
# adapted for 2.7 by Michal Pokorny
66
import sys
7-
from typing import overload, List, Any, AnyStr, Sequence, Tuple, BinaryIO, TextIO
7+
from typing import (
8+
overload, List, Any, AnyStr, Sequence, Tuple, BinaryIO, TextIO,
9+
TypeVar, Union, Text, Callable
10+
)
11+
12+
_T = TypeVar('_T')
13+
_PathType = Union[bytes, Text]
814

915
# ----- os.path variables -----
1016
supports_unicode_filenames = False
@@ -25,26 +31,29 @@ def basename(path: AnyStr) -> AnyStr: ...
2531
if sys.version_info >= (3, 5):
2632
def commonpath(paths: Sequence[AnyStr]) -> AnyStr: ...
2733

28-
# NOTE: Empty List[bytes] results in '' (str) => fall back to Any return type.
29-
def commonprefix(list: List[AnyStr]) -> Any: ...
34+
# NOTE: Empty lists results in '' (str) regardless of contained type.
35+
# Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes
36+
# So, fall back to Any
37+
def commonprefix(list: Sequence[AnyStr]) -> Any: ...
38+
3039
def dirname(path: AnyStr) -> AnyStr: ...
31-
def exists(path: AnyStr) -> bool: ...
32-
def lexists(path: AnyStr) -> bool: ...
40+
def exists(path: _PathType) -> bool: ...
41+
def lexists(path: _PathType) -> bool: ...
3342
def expanduser(path: AnyStr) -> AnyStr: ...
3443
def expandvars(path: AnyStr) -> AnyStr: ...
3544

45+
# These return float if os.stat_float_times() == True,
46+
# but int is a subclass of float.
47+
def getatime(path: _PathType) -> float: ...
48+
def getmtime(path: _PathType) -> float: ...
49+
def getctime(path: _PathType) -> float: ...
3650

37-
# These return float if os.stat_float_times() == True
38-
def getatime(path: AnyStr) -> Any: ...
39-
def getmtime(path: AnyStr) -> Any: ...
40-
def getctime(path: AnyStr) -> Any: ...
41-
42-
def getsize(path: AnyStr) -> int: ...
43-
def isabs(path: AnyStr) -> bool: ...
44-
def isfile(path: AnyStr) -> bool: ...
45-
def isdir(path: AnyStr) -> bool: ...
46-
def islink(path: AnyStr) -> bool: ...
47-
def ismount(path: AnyStr) -> bool: ...
51+
def getsize(path: _PathType) -> int: ...
52+
def isabs(path: _PathType) -> bool: ...
53+
def isfile(path: _PathType) -> bool: ...
54+
def isdir(path: _PathType) -> bool: ...
55+
def islink(path: _PathType) -> bool: ...
56+
def ismount(path: _PathType) -> bool: ...
4857

4958
def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ...
5059

@@ -53,13 +62,17 @@ def normpath(path: AnyStr) -> AnyStr: ...
5362
def realpath(path: AnyStr) -> AnyStr: ...
5463
def relpath(path: AnyStr, start: AnyStr = ...) -> AnyStr: ...
5564

56-
def samefile(path1: AnyStr, path2: AnyStr) -> bool: ...
65+
def samefile(path1: _PathType, path2: _PathType) -> bool: ...
5766
def sameopenfile(fp1: int, fp2: int) -> bool: ...
67+
# TODO
5868
# def samestat(stat1: stat_result,
5969
# stat2: stat_result) -> bool: ... # Unix only
6070

6171
def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
6272
def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
6373
def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
6474

65-
# def splitunc(path: str) -> Tuple[str, str]: ... # Windows only, deprecated
75+
def splitunc(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # Windows only, deprecated
76+
77+
if sys.version_info < (3,):
78+
def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ...

0 commit comments

Comments
 (0)