@@ -8,7 +8,7 @@ from io import TextIOWrapper as _TextIOWrapper
8
8
import sys
9
9
from typing import (
10
10
Mapping , MutableMapping , Dict , List , Any , Tuple , Iterator , overload , Union , AnyStr ,
11
- Optional , Generic , Set , Callable
11
+ Optional , Generic , Set , Callable , Text
12
12
)
13
13
from . import path
14
14
from mypy_extensions import NoReturn
@@ -117,6 +117,7 @@ if sys.version_info >= (3, 6):
117
117
class PathLike :
118
118
def __fspath__ (self ) -> AnyStr : ...
119
119
120
+ _PathType = Union [bytes , Text ]
120
121
121
122
if sys .version_info >= (3 , 5 ):
122
123
class DirEntry :
@@ -226,7 +227,7 @@ def setuid(uid: int) -> None: ... # Unix only
226
227
def strerror (code : int ) -> str : ...
227
228
def umask (mask : int ) -> int : ...
228
229
def uname () -> Tuple [str , str , str , str , str ]: ... # Unix only
229
- def unsetenv (key : AnyStr ) -> None : ...
230
+ def unsetenv (key : _PathType ) -> None : ...
230
231
# Return IO or TextIO
231
232
def fdopen (fd : int , mode : str = ..., buffering : int = ..., encoding : str = ...,
232
233
errors : str = ..., newline : str = ..., closefd : bool = ...) -> Any : ...
@@ -245,82 +246,81 @@ def fsync(fd: int) -> None: ...
245
246
def ftruncate (fd : int , length : int ) -> None : ... # Unix only
246
247
def isatty (fd : int ) -> bool : ... # Unix only
247
248
def lseek (fd : int , pos : int , how : int ) -> int : ...
248
- def open (file : AnyStr , flags : int , mode : int = ...) -> int : ...
249
+ def open (file : _PathType , flags : int , mode : int = ...) -> int : ...
249
250
def openpty () -> Tuple [int , int ]: ... # some flavors of Unix
250
251
def pipe () -> Tuple [int , int ]: ...
251
252
def read (fd : int , n : int ) -> bytes : ...
252
253
def tcgetpgrp (fd : int ) -> int : ... # Unix only
253
254
def tcsetpgrp (fd : int , pg : int ) -> None : ... # Unix only
254
255
def ttyname (fd : int ) -> str : ... # Unix only
255
256
def write (fd : int , string : bytes ) -> int : ...
256
- def access (path : AnyStr , mode : int ) -> bool : ...
257
- def chdir (path : AnyStr ) -> None : ...
257
+ def access (path : _PathType , mode : int ) -> bool : ...
258
+ def chdir (path : _PathType ) -> None : ...
258
259
def fchdir (fd : int ) -> None : ...
259
260
def getcwd () -> str : ...
260
261
def getcwdb () -> bytes : ...
261
- def chflags (path : str , flags : int ) -> None : ... # Unix only
262
- def chroot (path : str ) -> None : ... # Unix only
263
- def chmod (path : AnyStr , mode : int ) -> None : ...
264
- def chown (path : AnyStr , uid : int , gid : int ) -> None : ... # Unix only
265
- def lchflags (path : str , flags : int ) -> None : ... # Unix only
266
- def lchmod (path : str , mode : int ) -> None : ... # Unix only
267
- def lchown (path : str , uid : int , gid : int ) -> None : ... # Unix only
268
- def link (src : AnyStr , link_name : AnyStr ) -> None : ...
262
+ def chflags (path : _PathType , flags : int ) -> None : ... # Unix only
263
+ def chroot (path : _PathType ) -> None : ... # Unix only
264
+ def chmod (path : _PathType , mode : int ) -> None : ...
265
+ def chown (path : _PathType , uid : int , gid : int ) -> None : ... # Unix only
266
+ def lchflags (path : _PathType , flags : int ) -> None : ... # Unix only
267
+ def lchmod (path : _PathType , mode : int ) -> None : ... # Unix only
268
+ def lchown (path : _PathType , uid : int , gid : int ) -> None : ... # Unix only
269
+ def link (src : _PathType , link_name : _PathType ) -> None : ...
269
270
270
271
@overload
271
272
def listdir (path : str = ...) -> List [str ]: ...
272
273
@overload
273
274
def listdir (path : bytes ) -> List [bytes ]: ...
274
275
275
- def lstat (path : AnyStr ) -> stat_result : ...
276
- def mkfifo (path : str , mode : int = ...) -> None : ... # Unix only
277
- def mknod (filename : AnyStr , mode : int = ..., device : int = ...) -> None : ...
276
+ def lstat (path : _PathType ) -> stat_result : ...
277
+ def mkfifo (path : _PathType , mode : int = ...) -> None : ... # Unix only
278
+ def mknod (filename : _PathType , mode : int = ..., device : int = ...) -> None : ...
278
279
def major (device : int ) -> int : ...
279
280
def minor (device : int ) -> int : ...
280
281
def makedev (major : int , minor : int ) -> int : ...
281
- def mkdir (path : AnyStr , mode : int = ...) -> None : ...
282
- def makedirs (path : AnyStr , mode : int = ...,
282
+ def mkdir (path : _PathType , mode : int = ...) -> None : ...
283
+ def makedirs (path : _PathType , mode : int = ...,
283
284
exist_ok : bool = ...) -> None : ...
284
- def pathconf (path : str , name : str ) -> int : ... # Unix only
285
+ def pathconf (path : _PathType , name : str ) -> int : ... # Unix only
285
286
def readlink (path : AnyStr ) -> AnyStr : ...
286
- def remove (path : AnyStr ) -> None : ...
287
- def removedirs (path : AnyStr ) -> None : ...
288
- def rename (src : AnyStr , dst : AnyStr ) -> None : ...
289
- def renames (old : AnyStr , new : AnyStr ) -> None : ...
287
+ def remove (path : _PathType ) -> None : ...
288
+ def removedirs (path : _PathType ) -> None : ...
289
+ def rename (src : _PathType , dst : _PathType ) -> None : ...
290
+ def renames (old : _PathType , new : _PathType ) -> None : ...
290
291
if sys .version_info >= (3 , 3 ):
291
- def replace (src : AnyStr , dst : AnyStr ) -> None : ...
292
- def rmdir (path : AnyStr ) -> None : ...
292
+ def replace (src : _PathType , dst : _PathType ) -> None : ...
293
+ def rmdir (path : _PathType ) -> None : ...
293
294
if sys .version_info >= (3 , 5 ):
294
295
@overload
295
296
def scandir (path : str = ...) -> Iterator [DirEntry ]: ...
296
297
@overload
297
298
def scandir (path : bytes ) -> Iterator [DirEntry ]: ...
298
- def stat (path : AnyStr ) -> stat_result : ...
299
+ def stat (path : _PathType ) -> stat_result : ...
299
300
def stat_float_times (newvalue : Union [bool , None ] = ...) -> bool : ...
300
- def statvfs (path : str ) -> statvfs_result : ... # Unix only
301
- def symlink (source : AnyStr , link_name : AnyStr ,
301
+ def statvfs (path : _PathType ) -> statvfs_result : ... # Unix only
302
+ def symlink (source : _PathType , link_name : _PathType ,
302
303
target_is_directory : bool = ...) -> None :
303
304
... # final argument in Windows only
304
- def unlink (path : AnyStr ) -> None : ...
305
- def utime (path : AnyStr , times : Union [Tuple [int , int ], Tuple [float , float ]] = ...) -> None : ...
305
+ def unlink (path : _PathType ) -> None : ...
306
+ def utime (path : _PathType , times : Union [Tuple [int , int ], Tuple [float , float ]] = ...) -> None : ...
306
307
307
308
# TODO onerror: function from OSError to void
308
309
def walk (top : AnyStr , topdown : bool = ..., onerror : Any = ...,
309
310
followlinks : bool = ...) -> Iterator [Tuple [AnyStr , List [AnyStr ],
310
311
List [AnyStr ]]]: ...
311
312
312
313
def abort () -> 'None' : ...
313
- def execl (path : AnyStr , arg0 : AnyStr , * args : AnyStr ) -> None : ...
314
- def execle (path : AnyStr , arg0 : AnyStr ,
314
+ def execl (path : _PathType , arg0 : Union [ bytes , Text ], * args : Union [ bytes , Text ] ) -> None : ...
315
+ def execle (path : _PathType , arg0 : Union [ bytes , Text ] ,
315
316
* args : Any ) -> None : ... # Imprecise signature
316
- def execlp (path : AnyStr , arg0 : AnyStr , * args : AnyStr ) -> None : ...
317
- def execlpe (path : AnyStr , arg0 : AnyStr ,
317
+ def execlp (path : _PathType , arg0 : Union [ bytes , Text ], * args : Union [ bytes , Text ] ) -> None : ...
318
+ def execlpe (path : _PathType , arg0 : Union [ bytes , Text ] ,
318
319
* args : Any ) -> None : ... # Imprecise signature
319
- def execv (path : AnyStr , args : Union [Tuple [AnyStr ], List [AnyStr ]]) -> None : ...
320
- def execve (path : AnyStr , args : Union [Tuple [AnyStr ], List [AnyStr ]], env : Mapping [AnyStr , AnyStr ]) -> None : ...
321
- def execvp (file : AnyStr , args : Union [Tuple [AnyStr ], List [AnyStr ]]) -> None : ...
322
- def execvpe (file : AnyStr , args : Union [Tuple [AnyStr ], List [AnyStr ]],
323
- env : Mapping [str , str ]) -> None : ...
320
+ def execv (path : _PathType , args : Union [Tuple [Union [bytes , Text ]], List [Union [bytes , Text ]]]) -> None : ...
321
+ def execve (path : _PathType , args : Union [Tuple [Union [bytes , Text ]], List [Union [bytes , Text ]]], env : Mapping [str , str ]) -> None : ...
322
+ def execvp (file : _PathType , args : Union [Tuple [Union [bytes , Text ]], List [Union [bytes , Text ]]]) -> None : ...
323
+ def execvpe (file : _PathType , args : Union [Tuple [Union [bytes , Text ]], List [Union [bytes , Text ]]], env : Mapping [str , str ]) -> None : ...
324
324
def _exit (n : int ) -> NoReturn : ...
325
325
def fork () -> int : ... # Unix only
326
326
def forkpty () -> Tuple [int , int ]: ... # some flavors of Unix
@@ -335,22 +335,22 @@ class popen(_TextIOWrapper):
335
335
bufsize : int = ...) -> None : ...
336
336
def close (self ) -> Any : ... # may return int
337
337
338
- def spawnl (mode : int , path : AnyStr , arg0 : AnyStr , * args : AnyStr ) -> int : ...
339
- def spawnle (mode : int , path : AnyStr , arg0 : AnyStr ,
338
+ def spawnl (mode : int , path : _PathType , arg0 : Union [ bytes , Text ], * args : Union [ bytes , Text ] ) -> int : ...
339
+ def spawnle (mode : int , path : _PathType , arg0 : Union [ bytes , Text ] ,
340
340
* args : Any ) -> int : ... # Imprecise sig
341
- def spawnlp (mode : int , file : AnyStr , arg0 : AnyStr ,
342
- * args : AnyStr ) -> int : ... # Unix only TODO
343
- def spawnlpe (mode : int , file : AnyStr , arg0 : AnyStr , * args : Any ) -> int :
341
+ def spawnlp (mode : int , file : _PathType , arg0 : Union [ bytes , Text ] ,
342
+ * args : Union [ bytes , Text ] ) -> int : ... # Unix only TODO
343
+ def spawnlpe (mode : int , file : _PathType , arg0 : Union [ bytes , Text ] , * args : Any ) -> int :
344
344
... # Imprecise signature; Unix only TODO
345
- def spawnv (mode : int , path : AnyStr , args : List [AnyStr ]) -> int : ...
346
- def spawnve (mode : int , path : AnyStr , args : List [AnyStr ],
345
+ def spawnv (mode : int , path : _PathType , args : List [Union [ bytes , Text ] ]) -> int : ...
346
+ def spawnve (mode : int , path : _PathType , args : List [Union [ bytes , Text ] ],
347
347
env : Mapping [str , str ]) -> int : ...
348
- def spawnvp (mode : int , file : AnyStr , args : List [AnyStr ]) -> int : ... # Unix only
349
- def spawnvpe (mode : int , file : AnyStr , args : List [AnyStr ],
348
+ def spawnvp (mode : int , file : _PathType , args : List [Union [ bytes , Text ] ]) -> int : ... # Unix only
349
+ def spawnvpe (mode : int , file : _PathType , args : List [Union [ bytes , Text ] ],
350
350
env : Mapping [str , str ]) -> int :
351
351
... # Unix only
352
- def startfile (path : str , operation : Union [str , None ] = ...) -> None : ... # Windows only
353
- def system (command : AnyStr ) -> int : ...
352
+ def startfile (path : _PathType , operation : Optional [str ] = ...) -> None : ... # Windows only
353
+ def system (command : _PathType ) -> int : ...
354
354
def times () -> Tuple [float , float , float , float , float ]: ...
355
355
def wait () -> Tuple [int , int ]: ... # Unix only
356
356
def waitpid (pid : int , options : int ) -> Tuple [int , int ]: ...
@@ -381,7 +381,7 @@ WNOWAIT = 0
381
381
if sys .version_info >= (3 , 3 ):
382
382
def sync () -> None : ... # Unix only
383
383
384
- def truncate (path : Union [AnyStr , int ], length : int ) -> None : ... # Unix only up to version 3.4
384
+ def truncate (path : Union [_PathType , int ], length : int ) -> None : ... # Unix only up to version 3.4
385
385
386
386
def fwalk (top : AnyStr = ..., topdown : bool = ...,
387
387
onerror : Callable = ..., * , follow_symlinks : bool = ...,
0 commit comments