1 # NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent!
\r
3 # Ron Murawski <ron@horizonchess.com>
\r
5 from posix import stat_result
\r
8 overload, List, Any, AnyStr, Sequence, Tuple, BinaryIO, TextIO,
\r
9 TypeVar, Union, Text, Callable, Optional
\r
14 if sys.version_info >= (3, 6):
\r
15 from builtins import _PathLike
\r
16 _PathType = Union[bytes, Text, _PathLike]
\r
17 _StrPath = Union[Text, _PathLike[Text]]
\r
18 _BytesPath = Union[bytes, _PathLike[bytes]]
\r
20 _PathType = Union[bytes, Text]
\r
24 # ----- os.path variables -----
\r
25 supports_unicode_filenames: bool
\r
26 # aliases (also in os)
\r
36 # ----- os.path function stubs -----
\r
37 if sys.version_info >= (3, 6):
\r
38 # Overloads are necessary to work around python/mypy#3644.
\r
40 def abspath(path: _PathLike[AnyStr]) -> AnyStr: ...
\r
42 def abspath(path: AnyStr) -> AnyStr: ...
\r
44 def basename(path: _PathLike[AnyStr]) -> AnyStr: ...
\r
46 def basename(path: AnyStr) -> AnyStr: ...
\r
48 def dirname(path: _PathLike[AnyStr]) -> AnyStr: ...
\r
50 def dirname(path: AnyStr) -> AnyStr: ...
\r
52 def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ...
\r
54 def expanduser(path: AnyStr) -> AnyStr: ...
\r
56 def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ...
\r
58 def expandvars(path: AnyStr) -> AnyStr: ...
\r
60 def normcase(path: _PathLike[AnyStr]) -> AnyStr: ...
\r
62 def normcase(path: AnyStr) -> AnyStr: ...
\r
64 def normpath(path: _PathLike[AnyStr]) -> AnyStr: ...
\r
66 def normpath(path: AnyStr) -> AnyStr: ...
\r
67 if sys.platform == 'win32':
\r
69 def realpath(path: _PathLike[AnyStr]) -> AnyStr: ...
\r
71 def realpath(path: AnyStr) -> AnyStr: ...
\r
74 def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ...
\r
76 def realpath(filename: AnyStr) -> AnyStr: ...
\r
79 def abspath(path: AnyStr) -> AnyStr: ...
\r
80 def basename(path: AnyStr) -> AnyStr: ...
\r
81 def dirname(path: AnyStr) -> AnyStr: ...
\r
82 def expanduser(path: AnyStr) -> AnyStr: ...
\r
83 def expandvars(path: AnyStr) -> AnyStr: ...
\r
84 def normcase(path: AnyStr) -> AnyStr: ...
\r
85 def normpath(path: AnyStr) -> AnyStr: ...
\r
86 if sys.platform == 'win32':
\r
87 def realpath(path: AnyStr) -> AnyStr: ...
\r
89 def realpath(filename: AnyStr) -> AnyStr: ...
\r
91 if sys.version_info >= (3, 6):
\r
92 # In reality it returns str for sequences of _StrPath and bytes for sequences
\r
93 # of _BytesPath, but mypy does not accept such a signature.
\r
94 def commonpath(paths: Sequence[_PathType]) -> Any: ...
\r
95 elif sys.version_info >= (3, 5):
\r
96 def commonpath(paths: Sequence[AnyStr]) -> AnyStr: ...
\r
98 # NOTE: Empty lists results in '' (str) regardless of contained type.
\r
99 # Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes
\r
100 # So, fall back to Any
\r
101 def commonprefix(list: Sequence[_PathType]) -> Any: ...
\r
103 def exists(path: _PathType) -> bool: ...
\r
104 def lexists(path: _PathType) -> bool: ...
\r
106 # These return float if os.stat_float_times() == True,
\r
107 # but int is a subclass of float.
\r
108 def getatime(path: _PathType) -> float: ...
\r
109 def getmtime(path: _PathType) -> float: ...
\r
110 def getctime(path: _PathType) -> float: ...
\r
112 def getsize(path: _PathType) -> int: ...
\r
113 def isabs(path: _PathType) -> bool: ...
\r
114 def isfile(path: _PathType) -> bool: ...
\r
115 def isdir(path: _PathType) -> bool: ...
\r
116 def islink(path: _PathType) -> bool: ...
\r
117 def ismount(path: _PathType) -> bool: ...
\r
119 if sys.version_info < (3, 0):
\r
120 # Make sure signatures are disjunct, and allow combinations of bytes and unicode.
\r
121 # (Since Python 2 allows that, too)
\r
122 # Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in
\r
125 def join(__p1: bytes, *p: bytes) -> bytes: ...
\r
127 def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ...
\r
129 def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ...
\r
131 def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ...
\r
133 def join(__p1: Text, *p: _PathType) -> Text: ...
\r
134 elif sys.version_info >= (3, 6):
\r
135 # Mypy complains that the signatures overlap (same for relpath below), but things seem to behave correctly anyway.
\r
137 def join(path: _StrPath, *paths: _StrPath) -> Text: ... # type: ignore
\r
139 def join(path: _BytesPath, *paths: _BytesPath) -> bytes: ...
\r
141 def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ...
\r
144 def relpath(path: _BytesPath, start: Optional[_BytesPath] = ...) -> bytes: ... # type: ignore
\r
146 def relpath(path: _StrPath, start: Optional[_StrPath] = ...) -> Text: ...
\r
148 def samefile(path1: _PathType, path2: _PathType) -> bool: ...
\r
149 def sameopenfile(fp1: int, fp2: int) -> bool: ...
\r
150 def samestat(stat1: stat_result, stat2: stat_result) -> bool: ...
\r
152 if sys.version_info >= (3, 6):
\r
154 def split(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
\r
156 def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
\r
158 def splitdrive(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
\r
160 def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
\r
162 def splitext(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
\r
164 def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
\r
166 def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
\r
167 def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
\r
168 def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
\r
170 def splitunc(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # Windows only, deprecated
\r
172 if sys.version_info < (3,):
\r
173 def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ...
\r