2
2
# Ron Murawski <[email protected] >
3
3
4
4
# based on http://docs.python.org/3.2/library/os.path.html
5
-
5
+ # adapted for 2.7 by Michal Pokorny
6
6
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 ]
8
14
9
15
# ----- os.path variables -----
10
16
supports_unicode_filenames = False
@@ -25,26 +31,29 @@ def basename(path: AnyStr) -> AnyStr: ...
25
31
if sys .version_info >= (3 , 5 ):
26
32
def commonpath (paths : Sequence [AnyStr ]) -> AnyStr : ...
27
33
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
+
30
39
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 : ...
33
42
def expanduser (path : AnyStr ) -> AnyStr : ...
34
43
def expandvars (path : AnyStr ) -> AnyStr : ...
35
44
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 : ...
36
50
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 : ...
48
57
49
58
def join (path : AnyStr , * paths : AnyStr ) -> AnyStr : ...
50
59
@@ -53,13 +62,17 @@ def normpath(path: AnyStr) -> AnyStr: ...
53
62
def realpath (path : AnyStr ) -> AnyStr : ...
54
63
def relpath (path : AnyStr , start : AnyStr = ...) -> AnyStr : ...
55
64
56
- def samefile (path1 : AnyStr , path2 : AnyStr ) -> bool : ...
65
+ def samefile (path1 : _PathType , path2 : _PathType ) -> bool : ...
57
66
def sameopenfile (fp1 : int , fp2 : int ) -> bool : ...
67
+ # TODO
58
68
# def samestat(stat1: stat_result,
59
69
# stat2: stat_result) -> bool: ... # Unix only
60
70
61
71
def split (path : AnyStr ) -> Tuple [AnyStr , AnyStr ]: ...
62
72
def splitdrive (path : AnyStr ) -> Tuple [AnyStr , AnyStr ]: ...
63
73
def splitext (path : AnyStr ) -> Tuple [AnyStr , AnyStr ]: ...
64
74
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