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
66import 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 -----
1016supports_unicode_filenames = False
@@ -25,26 +31,29 @@ def basename(path: AnyStr) -> AnyStr: ...
2531if 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+
3039def 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 : ...
3342def expanduser (path : AnyStr ) -> AnyStr : ...
3443def 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
4958def join (path : AnyStr , * paths : AnyStr ) -> AnyStr : ...
5059
@@ -53,13 +62,17 @@ def normpath(path: AnyStr) -> AnyStr: ...
5362def realpath (path : AnyStr ) -> AnyStr : ...
5463def relpath (path : AnyStr , start : AnyStr = ...) -> AnyStr : ...
5564
56- def samefile (path1 : AnyStr , path2 : AnyStr ) -> bool : ...
65+ def samefile (path1 : _PathType , path2 : _PathType ) -> bool : ...
5766def sameopenfile (fp1 : int , fp2 : int ) -> bool : ...
67+ # TODO
5868# def samestat(stat1: stat_result,
5969# stat2: stat_result) -> bool: ... # Unix only
6070
6171def split (path : AnyStr ) -> Tuple [AnyStr , AnyStr ]: ...
6272def splitdrive (path : AnyStr ) -> Tuple [AnyStr , AnyStr ]: ...
6373def 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