Enable pyi-stubs for os (PY-23258, PY-21395, PY-21394, PY-21397, PY-17420, PY-28984, PY-27584)

GitOrigin-RevId: 34ecf07bc68276e62315d01f3c3347f79026ec65
This commit is contained in:
Semyon Proshev
2019-11-20 11:37:02 +00:00
committed by intellij-monorepo-bot
parent 6db6ad9f51
commit cff3f1f86d
43 changed files with 2497 additions and 3649 deletions
File diff suppressed because it is too large Load Diff
-293
View File
@@ -1,293 +0,0 @@
"""Skeleton for 'os.path' stdlib module."""
import sys
import os
def abspath(path):
"""Return a normalized absolutized version of the pathname path.
:type path: bytes | unicode | os.PathLike
:rtype: bytes | unicode
"""
return path
def basename(path):
"""Return the base name of pathname path.
:type path: bytes | unicode | os.PathLike
:rtype: bytes | unicode
"""
return path
def commonprefix(list):
"""Return the longest path prefix (taken character-by-character) that is a
prefix of all paths in list.
:type list: collections.Iterable[bytes | unicode | os.PathLike]
:rtype: bytes | unicode
"""
pass
def dirname(path):
"""Return the directory name of pathname path.
:type path: bytes | unicode | os.PathLike
:rtype: bytes | unicode
"""
return path
def exists(path):
"""Return True if path refers to an existing path. Returns False for broken
symbolic links.
:type path: bytes | unicode | os.PathLike
:rtype: bool
"""
return False
def lexists(path):
"""Return True if path refers to an existing path. Returns True for broken
symbolic links.
:type path: bytes | unicode | os.PathLike
:rtype: bool
"""
return False
def expanduser(path):
"""On Unix and Windows, return the argument with an initial component of ~
or ~user replaced by that user's home directory.
:type path: bytes | unicode | os.PathLike
:rtype: bytes | unicode
"""
return path
def expandvars(path):
"""Return the argument with environment variables expanded.
:type path: bytes | unicode | os.PathLike
:rtype: bytes | unicode
"""
return path
def getatime(path):
"""Return the time of last access of path.
:type path: bytes | unicode | os.PathLike
:rtype: float
"""
return 0.0
def getmtime(path):
"""Return the time of last modification of path.
:type path: bytes | unicode | os.PathLike
:rtype: float
"""
return 0.0
def getctime(path):
"""Return the system's ctime.
:type path: bytes | unicode | os.PathLike
:rtype: float
"""
return 0.0
def getsize(path):
"""Return the size, in bytes, of path.
:type path: bytes | unicode | os.PathLike
:rtype: int
"""
return 0
def isabs(path):
"""Return True if path is an absolute pathname.
:type path: bytes | unicode | os.PathLike
:rtype: bool
"""
return False
def isfile(path):
"""Return True if path is an existing regular file.
:type path: bytes | unicode | os.PathLike
:rtype: bool
"""
return False
def isdir(path):
"""Return True if path is an existing directory.
:type path: bytes | unicode | os.PathLike
:rtype: bool
"""
return False
def islink(path):
"""Return True if path refers to a directory entry that is a symbolic link.
:type path: bytes | unicode | os.PathLike
:rtype: bool
"""
return False
def ismount(path):
"""Return True if pathname path is a mount point: a point in a file system
where a different file system has been mounted.
:type path: bytes | unicode | os.PathLike
:rtype: bool
"""
return False
def join(path, *paths):
"""Join one or more path components intelligently.
:type path: bytes | unicode | os.PathLike
:type paths: collections.Iterable[bytes | unicode | os.PathLike]
:rtype: bytes | unicode
"""
return path
def normcase(path):
"""Normalize the case of a pathname.
:type path: bytes | unicode | os.PathLike
:rtype: bytes | unicode
"""
return path
def normpath(path):
"""Normalize a pathname by collapsing redundant separators and up-level
references.
:type path: bytes | unicode | os.PathLike
:rtype: bytes | unicode
"""
return path
def realpath(path):
"""Return the canonical path of the specified filename, eliminating any
symbolic links encountered in the path.
:type path: bytes | unicode | os.PathLike
:rtype: bytes | unicode
"""
return path
def relpath(path, start=os.curdir):
"""Return a relative filepath to path either from the current directory or
from an optional start directory.
:type path: bytes | unicode | os.PathLike
:type start: bytes | unicode | os.PathLike
:rtype: bytes | unicode
"""
return path
def samefile(path1, path2):
"""Return True if both pathname arguments refer to the same file or
directory.
:type path1: bytes | unicode | os.PathLike
:type path2: bytes | unicode | os.PathLike
:rtype: bool
"""
return False
def sameopenfile(fp1, fp2):
"""Return True if the file descriptors fp1 and fp2 refer to the same file.
:type fp1: int
:type fp2: int
:rtype: bool
"""
return False
def samestat(stat1, stat2):
"""Return True if the stat tuples stat1 and stat2 refer to the same file.
:type stat1: os.stat_result | tuple
:type stat2: os.stat_result | tuple
:rtype: bool
"""
return False
def split(path):
"""Split the pathname path into a pair, (head, tail).
:type path: bytes | unicode | os.PathLike
:rtype: (bytes | unicode, bytes | unicode)
"""
return path, path
def splitdrive(path):
"""Split the pathname path into a pair (drive, tail).
:type path: bytes | unicode | os.PathLike
:rtype: (bytes | unicode, bytes | unicode)
"""
return path, path
def splitext(path):
"""Split the pathname path into a pair (root, ext).
:type path: bytes | unicode | os.PathLike
:rtype: (bytes | unicode, bytes | unicode)
"""
return path, path
def splitunc(path):
"""Split the pathname path into a pair (unc, rest).
:type path: bytes | unicode | os.PathLike
:rtype: (bytes | unicode, bytes | unicode)
"""
return path, path
if sys.version_info < (3, 0):
def walk(path, visit, arg):
"""Calls the function visit with arguments (arg, dirname, names) for
each directory in the directory tree rooted at path.
:type path: T <= bytes | unicode
:type visit: (V, T, list[T]) -> None
:type arg: V
:rtype: None
"""
pass
@@ -0,0 +1,368 @@
# Stubs for os
# Ron Murawski <ron@horizonchess.com>
from builtins import OSError as error
from io import TextIOWrapper as _TextIOWrapper
from posix import listdir as listdir, stat_result as stat_result # TODO: use this, see https://github.com/python/mypy/issues/3078
import sys
from typing import (
Mapping, MutableMapping, Dict, List, Any, Tuple, Iterator, overload, Union, AnyStr,
Optional, Generic, Set, Callable, Text, Sequence, IO, NamedTuple, NoReturn, TypeVar
)
from . import path as path
_T = TypeVar('_T')
# ----- os variables -----
if sys.version_info >= (3, 2):
supports_bytes_environ: bool
if sys.version_info >= (3, 3):
supports_dir_fd: Set[Callable[..., Any]]
supports_fd: Set[Callable[..., Any]]
supports_effective_ids: Set[Callable[..., Any]]
supports_follow_symlinks: Set[Callable[..., Any]]
SEEK_SET: int
SEEK_CUR: int
SEEK_END: int
O_RDONLY: int
O_WRONLY: int
O_RDWR: int
O_APPEND: int
O_CREAT: int
O_EXCL: int
O_TRUNC: int
# We don't use sys.platform for O_* flags to denote platform-dependent APIs because some codes,
# including tests for mypy, use a more finer way than sys.platform before using these APIs
# See https://github.com/python/typeshed/pull/2286 for discussions
O_DSYNC: int # Unix only
O_RSYNC: int # Unix only
O_SYNC: int # Unix only
O_NDELAY: int # Unix only
O_NONBLOCK: int # Unix only
O_NOCTTY: int # Unix only
O_SHLOCK: int # Unix only
O_EXLOCK: int # Unix only
O_BINARY: int # Windows only
O_NOINHERIT: int # Windows only
O_SHORT_LIVED: int # Windows only
O_TEMPORARY: int # Windows only
O_RANDOM: int # Windows only
O_SEQUENTIAL: int # Windows only
O_TEXT: int # Windows only
O_ASYNC: int # Gnu extension if in C library
O_DIRECT: int # Gnu extension if in C library
O_DIRECTORY: int # Gnu extension if in C library
O_NOFOLLOW: int # Gnu extension if in C library
O_NOATIME: int # Gnu extension if in C library
O_LARGEFILE: int # Gnu extension if in C library
curdir: str
pardir: str
sep: str
if sys.platform == 'win32':
altsep: str
else:
altsep: Optional[str]
extsep: str
pathsep: str
defpath: str
linesep: str
devnull: str
name: str
F_OK: int
R_OK: int
W_OK: int
X_OK: int
class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]):
def copy(self) -> Dict[AnyStr, AnyStr]: ...
def __delitem__(self, key: AnyStr) -> None: ...
def __getitem__(self, key: AnyStr) -> AnyStr: ...
def __setitem__(self, key: AnyStr, value: AnyStr) -> None: ...
def __iter__(self) -> Iterator[AnyStr]: ...
def __len__(self) -> int: ...
environ: _Environ[str]
if sys.version_info >= (3, 2):
environb: _Environ[bytes]
if sys.platform != 'win32':
# Unix only
confstr_names: Dict[str, int]
pathconf_names: Dict[str, int]
sysconf_names: Dict[str, int]
EX_OK: int
EX_USAGE: int
EX_DATAERR: int
EX_NOINPUT: int
EX_NOUSER: int
EX_NOHOST: int
EX_UNAVAILABLE: int
EX_SOFTWARE: int
EX_OSERR: int
EX_OSFILE: int
EX_CANTCREAT: int
EX_IOERR: int
EX_TEMPFAIL: int
EX_PROTOCOL: int
EX_NOPERM: int
EX_CONFIG: int
EX_NOTFOUND: int
P_NOWAIT: int
P_NOWAITO: int
P_WAIT: int
if sys.platform == 'win32':
P_DETACH: int
P_OVERLAY: int
# wait()/waitpid() options
if sys.platform != 'win32':
WNOHANG: int # Unix only
WCONTINUED: int # some Unix systems
WUNTRACED: int # Unix only
TMP_MAX: int # Undocumented, but used by tempfile
# ----- os classes (structures) -----
if sys.version_info >= (3, 6):
from builtins import _PathLike as PathLike # See comment in builtins
_PathType = path._PathType
_StatVFS = NamedTuple('_StatVFS', [('f_bsize', int), ('f_frsize', int), ('f_blocks', int),
('f_bfree', int), ('f_bavail', int), ('f_files', int),
('f_ffree', int), ('f_favail', int), ('f_flag', int),
('f_namemax', int)])
def getlogin() -> str: ...
def getpid() -> int: ...
def getppid() -> int: ...
def strerror(code: int) -> str: ...
def umask(mask: int) -> int: ...
if sys.platform != 'win32':
def ctermid() -> str: ...
def getegid() -> int: ...
def geteuid() -> int: ...
def getgid() -> int: ...
def getgroups() -> List[int]: ... # Unix only, behaves differently on Mac
def initgroups(username: str, gid: int) -> None: ...
def getpgid(pid: int) -> int: ...
def getpgrp() -> int: ...
def getresuid() -> Tuple[int, int, int]: ...
def getresgid() -> Tuple[int, int, int]: ...
def getuid() -> int: ...
def setegid(egid: int) -> None: ...
def seteuid(euid: int) -> None: ...
def setgid(gid: int) -> None: ...
def setgroups(groups: Sequence[int]) -> None: ...
def setpgrp() -> None: ...
def setpgid(pid: int, pgrp: int) -> None: ...
def setregid(rgid: int, egid: int) -> None: ...
def setresgid(rgid: int, egid: int, sgid: int) -> None: ...
def setresuid(ruid: int, euid: int, suid: int) -> None: ...
def setreuid(ruid: int, euid: int) -> None: ...
def getsid(pid: int) -> int: ...
def setsid() -> None: ...
def setuid(uid: int) -> None: ...
def uname() -> Tuple[str, str, str, str, str]: ...
@overload
def getenv(key: Text) -> Optional[str]: ...
@overload
def getenv(key: Text, default: _T) -> Union[str, _T]: ...
def putenv(key: Union[bytes, Text], value: Union[bytes, Text]) -> None: ...
def unsetenv(key: Union[bytes, Text]) -> None: ...
def fdopen(fd: int, *args, **kwargs) -> IO[Any]: ...
def close(fd: int) -> None: ...
def closerange(fd_low: int, fd_high: int) -> None: ...
def dup(fd: int) -> int: ...
def dup2(fd: int, fd2: int) -> None: ...
def fstat(fd: int) -> Any: ...
def fsync(fd: int) -> None: ...
def lseek(fd: int, pos: int, how: int) -> int: ...
def open(file: _PathType, flags: int, mode: int = ...) -> int: ...
def pipe() -> Tuple[int, int]: ...
def read(fd: int, n: int) -> bytes: ...
def write(fd: int, string: Union[bytes, buffer]) -> int: ...
def access(path: _PathType, mode: int) -> bool: ...
def chdir(path: _PathType) -> None: ...
def fchdir(fd: int) -> None: ...
def getcwd() -> str: ...
def getcwdu() -> unicode: ...
def chmod(path: _PathType, mode: int) -> None: ...
def link(src: _PathType, link_name: _PathType) -> None: ...
def lstat(path: _PathType) -> Any: ...
def mknod(filename: _PathType, mode: int = ..., device: int = ...) -> None: ...
def major(device: int) -> int: ...
def minor(device: int) -> int: ...
def makedev(major: int, minor: int) -> int: ...
def mkdir(path: _PathType, mode: int = ...) -> None: ...
def makedirs(path: _PathType, mode: int = ...) -> None: ...
def readlink(path: AnyStr) -> AnyStr: ...
def remove(path: _PathType) -> None: ...
def removedirs(path: _PathType) -> None: ...
def rename(src: _PathType, dst: _PathType) -> None: ...
def renames(old: _PathType, new: _PathType) -> None: ...
def rmdir(path: _PathType) -> None: ...
def stat(path: _PathType) -> Any: ...
@overload
def stat_float_times() -> bool: ...
@overload
def stat_float_times(newvalue: bool) -> None: ...
def symlink(source: _PathType, link_name: _PathType) -> None: ...
def unlink(path: _PathType) -> None: ...
# TODO: add ns, dir_fd, follow_symlinks argument
if sys.version_info >= (3, 0):
def utime(path: _PathType, times: Optional[Tuple[float, float]] = ...) -> None: ...
else:
def utime(path: _PathType, times: Optional[Tuple[float, float]]) -> None: ...
if sys.platform != 'win32':
# Unix only
def fchmod(fd: int, mode: int) -> None: ...
def fchown(fd: int, uid: int, gid: int) -> None: ...
if sys.platform != 'darwin':
def fdatasync(fd: int) -> None: ... # Unix only, not Mac
def fpathconf(fd: int, name: Union[str, int]) -> int: ...
def fstatvfs(fd: int) -> _StatVFS: ...
def ftruncate(fd: int, length: int) -> None: ...
def isatty(fd: int) -> bool: ...
def openpty() -> Tuple[int, int]: ... # some flavors of Unix
def tcgetpgrp(fd: int) -> int: ...
def tcsetpgrp(fd: int, pg: int) -> None: ...
def ttyname(fd: int) -> str: ...
def chflags(path: _PathType, flags: int) -> None: ...
def chroot(path: _PathType) -> None: ...
def chown(path: _PathType, uid: int, gid: int) -> None: ...
def lchflags(path: _PathType, flags: int) -> None: ...
def lchmod(path: _PathType, mode: int) -> None: ...
def lchown(path: _PathType, uid: int, gid: int) -> None: ...
def mkfifo(path: _PathType, mode: int = ...) -> None: ...
def pathconf(path: _PathType, name: Union[str, int]) -> int: ...
def statvfs(path: _PathType) -> _StatVFS: ...
if sys.version_info >= (3, 6):
def walk(top: Union[AnyStr, PathLike[AnyStr]], topdown: bool = ...,
onerror: Optional[Callable[[OSError], Any]] = ...,
followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr],
List[AnyStr]]]: ...
else:
def walk(top: AnyStr, topdown: bool = ..., onerror: Optional[Callable[[OSError], Any]] = ...,
followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr],
List[AnyStr]]]: ...
def abort() -> NoReturn: ...
# These are defined as execl(file, *args) but the first *arg is mandatory.
def execl(file: _PathType, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ...
def execlp(file: _PathType, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ...
# These are: execle(file, *args, env) but env is pulled from the last element of the args.
def execle(file: _PathType, __arg0: Union[bytes, Text], *args: Any) -> NoReturn: ...
def execlpe(file: _PathType, __arg0: Union[bytes, Text], *args: Any) -> NoReturn: ...
# The docs say `args: tuple or list of strings`
# The implementation enforces tuple or list so we can't use Sequence.
_ExecVArgs = Union[Tuple[Union[bytes, Text], ...], List[bytes], List[Text], List[Union[bytes, Text]]]
def execv(path: _PathType, args: _ExecVArgs) -> NoReturn: ...
def execve(path: _PathType, args: _ExecVArgs, env: Mapping[str, str]) -> NoReturn: ...
def execvp(file: _PathType, args: _ExecVArgs) -> NoReturn: ...
def execvpe(file: _PathType, args: _ExecVArgs, env: Mapping[str, str]) -> NoReturn: ...
def _exit(n: int) -> NoReturn: ...
def kill(pid: int, sig: int) -> None: ...
if sys.platform != 'win32':
# Unix only
def fork() -> int: ...
def forkpty() -> Tuple[int, int]: ... # some flavors of Unix
def killpg(pgid: int, sig: int) -> None: ...
def nice(increment: int) -> int: ...
def plock(op: int) -> None: ... # ???op is int?
if sys.version_info >= (3, 0):
class popen(_TextIOWrapper):
# TODO 'b' modes or bytes command not accepted?
def __init__(self, command: str, mode: str = ...,
bufsize: int = ...) -> None: ...
def close(self) -> Any: ... # may return int
else:
def popen(command: str, *args, **kwargs) -> IO[Any]: ...
def popen2(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any]]: ...
def popen3(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any], IO[Any]]: ...
def popen4(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any]]: ...
def spawnl(mode: int, path: _PathType, arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> int: ...
def spawnle(mode: int, path: _PathType, arg0: Union[bytes, Text],
*args: Any) -> int: ... # Imprecise sig
def spawnv(mode: int, path: _PathType, args: List[Union[bytes, Text]]) -> int: ...
def spawnve(mode: int, path: _PathType, args: List[Union[bytes, Text]],
env: Mapping[str, str]) -> int: ...
def system(command: _PathType) -> int: ...
def times() -> Tuple[float, float, float, float, float]: ...
def waitpid(pid: int, options: int) -> Tuple[int, int]: ...
def urandom(n: int) -> bytes: ...
if sys.platform == 'win32':
def startfile(path: _PathType, operation: Optional[str] = ...) -> None: ...
else:
# Unix only
def spawnlp(mode: int, file: _PathType, arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> int: ...
def spawnlpe(mode: int, file: _PathType, arg0: Union[bytes, Text], *args: Any) -> int: ... # Imprecise signature
def spawnvp(mode: int, file: _PathType, args: List[Union[bytes, Text]]) -> int: ...
def spawnvpe(mode: int, file: _PathType, args: List[Union[bytes, Text]], env: Mapping[str, str]) -> int: ...
def wait() -> Tuple[int, int]: ...
def wait3(options: int) -> Tuple[int, int, Any]: ...
def wait4(pid: int, options: int) -> Tuple[int, int, Any]: ...
def WCOREDUMP(status: int) -> bool: ...
def WIFCONTINUED(status: int) -> bool: ...
def WIFSTOPPED(status: int) -> bool: ...
def WIFSIGNALED(status: int) -> bool: ...
def WIFEXITED(status: int) -> bool: ...
def WEXITSTATUS(status: int) -> int: ...
def WSTOPSIG(status: int) -> int: ...
def WTERMSIG(status: int) -> int: ...
def confstr(name: Union[str, int]) -> Optional[str]: ...
def getloadavg() -> Tuple[float, float, float]: ...
def sysconf(name: Union[str, int]) -> int: ...
if sys.version_info >= (3, 0):
def sched_getaffinity(id: int) -> Set[int]: ...
if sys.version_info >= (3, 3):
class waitresult:
si_pid: int
def waitid(idtype: int, id: int, options: int) -> waitresult: ...
if sys.version_info < (3, 0):
def tmpfile() -> IO[Any]: ...
def tmpnam() -> str: ...
def tempnam(dir: str = ..., prefix: str = ...) -> str: ...
P_ALL: int
WEXITED: int
WNOWAIT: int
if sys.version_info >= (3, 3):
if sys.platform != 'win32':
# Unix only
def sync() -> None: ...
def truncate(path: Union[_PathType, int], length: int) -> None: ... # Unix only up to version 3.4
def fwalk(top: AnyStr = ..., topdown: bool = ...,
onerror: Callable = ..., *, follow_symlinks: bool = ...,
dir_fd: int = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], List[AnyStr], int]]: ...
terminal_size = NamedTuple('terminal_size', [('columns', int), ('lines', int)])
def get_terminal_size(fd: int = ...) -> terminal_size: ...
if sys.version_info >= (3, 4):
def cpu_count() -> Optional[int]: ...
@@ -0,0 +1,177 @@
# NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent!
# Stubs for os.path
# Ron Murawski <ron@horizonchess.com>
import os
import sys
from typing import overload, List, Any, AnyStr, Sequence, Tuple, TypeVar, Union, Text, Callable, Optional
_T = TypeVar('_T')
if sys.version_info >= (3, 6):
from builtins import _PathLike
_PathType = Union[bytes, Text, _PathLike]
_StrPath = Union[Text, _PathLike[Text]]
_BytesPath = Union[bytes, _PathLike[bytes]]
else:
_PathType = Union[bytes, Text]
_StrPath = Text
_BytesPath = bytes
# ----- os.path variables -----
supports_unicode_filenames: bool
# aliases (also in os)
curdir: str
pardir: str
sep: str
if sys.platform == 'win32':
altsep: str
else:
altsep: Optional[str]
extsep: str
pathsep: str
defpath: str
devnull: str
# ----- os.path function stubs -----
if sys.version_info >= (3, 6):
# Overloads are necessary to work around python/mypy#3644.
@overload
def abspath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def abspath(path: AnyStr) -> AnyStr: ...
@overload
def basename(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def basename(path: AnyStr) -> AnyStr: ...
@overload
def dirname(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def dirname(path: AnyStr) -> AnyStr: ...
@overload
def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def expanduser(path: AnyStr) -> AnyStr: ...
@overload
def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def expandvars(path: AnyStr) -> AnyStr: ...
@overload
def normcase(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def normcase(path: AnyStr) -> AnyStr: ...
@overload
def normpath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def normpath(path: AnyStr) -> AnyStr: ...
if sys.platform == 'win32':
@overload
def realpath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def realpath(path: AnyStr) -> AnyStr: ...
else:
@overload
def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def realpath(filename: AnyStr) -> AnyStr: ...
else:
def abspath(path: AnyStr) -> AnyStr: ...
def basename(path: AnyStr) -> AnyStr: ...
def dirname(path: AnyStr) -> AnyStr: ...
def expanduser(path: AnyStr) -> AnyStr: ...
def expandvars(path: AnyStr) -> AnyStr: ...
def normcase(path: AnyStr) -> AnyStr: ...
def normpath(path: AnyStr) -> AnyStr: ...
if sys.platform == 'win32':
def realpath(path: AnyStr) -> AnyStr: ...
else:
def realpath(filename: AnyStr) -> AnyStr: ...
if sys.version_info >= (3, 6):
# In reality it returns str for sequences of _StrPath and bytes for sequences
# of _BytesPath, but mypy does not accept such a signature.
def commonpath(paths: Sequence[_PathType]) -> Any: ...
elif sys.version_info >= (3, 5):
def commonpath(paths: Sequence[AnyStr]) -> AnyStr: ...
# NOTE: Empty lists results in '' (str) regardless of contained type.
# Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes
# So, fall back to Any
def commonprefix(list: Sequence[_PathType]) -> Any: ...
if sys.version_info >= (3, 3):
def exists(path: Union[_PathType, int]) -> bool: ...
else:
def exists(path: _PathType) -> bool: ...
def lexists(path: _PathType) -> bool: ...
# These return float if os.stat_float_times() == True,
# but int is a subclass of float.
def getatime(path: _PathType) -> float: ...
def getmtime(path: _PathType) -> float: ...
def getctime(path: _PathType) -> float: ...
def getsize(path: _PathType) -> int: ...
def isabs(path: _PathType) -> bool: ...
def isfile(path: _PathType) -> bool: ...
def isdir(path: _PathType) -> bool: ...
def islink(path: _PathType) -> bool: ...
def ismount(path: _PathType) -> bool: ...
if sys.version_info < (3, 0):
# Make sure signatures are disjunct, and allow combinations of bytes and unicode.
# (Since Python 2 allows that, too)
# Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in
# a type error.
@overload
def join(__p1: bytes, *p: bytes) -> bytes: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: Text, *p: _PathType) -> Text: ...
elif sys.version_info >= (3, 6):
# Mypy complains that the signatures overlap (same for relpath below), but things seem to behave correctly anyway.
@overload
def join(path: _StrPath, *paths: _StrPath) -> Text: ...
@overload
def join(path: _BytesPath, *paths: _BytesPath) -> bytes: ...
else:
def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ...
@overload
def relpath(path: _BytesPath, start: Optional[_BytesPath] = ...) -> bytes: ...
@overload
def relpath(path: _StrPath, start: Optional[_StrPath] = ...) -> Text: ...
def samefile(path1: _PathType, path2: _PathType) -> bool: ...
def sameopenfile(fp1: int, fp2: int) -> bool: ...
def samestat(stat1: os.stat_result, stat2: os.stat_result) -> bool: ...
if sys.version_info >= (3, 6):
@overload
def split(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitdrive(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitext(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
else:
def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
if sys.platform == 'win32':
def splitunc(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated
if sys.version_info < (3,):
def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ...
@@ -0,0 +1,177 @@
# NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent!
# Stubs for os.path
# Ron Murawski <ron@horizonchess.com>
import os
import sys
from typing import overload, List, Any, AnyStr, Sequence, Tuple, TypeVar, Union, Text, Callable, Optional
_T = TypeVar('_T')
if sys.version_info >= (3, 6):
from builtins import _PathLike
_PathType = Union[bytes, Text, _PathLike]
_StrPath = Union[Text, _PathLike[Text]]
_BytesPath = Union[bytes, _PathLike[bytes]]
else:
_PathType = Union[bytes, Text]
_StrPath = Text
_BytesPath = bytes
# ----- os.path variables -----
supports_unicode_filenames: bool
# aliases (also in os)
curdir: str
pardir: str
sep: str
if sys.platform == 'win32':
altsep: str
else:
altsep: Optional[str]
extsep: str
pathsep: str
defpath: str
devnull: str
# ----- os.path function stubs -----
if sys.version_info >= (3, 6):
# Overloads are necessary to work around python/mypy#3644.
@overload
def abspath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def abspath(path: AnyStr) -> AnyStr: ...
@overload
def basename(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def basename(path: AnyStr) -> AnyStr: ...
@overload
def dirname(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def dirname(path: AnyStr) -> AnyStr: ...
@overload
def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def expanduser(path: AnyStr) -> AnyStr: ...
@overload
def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def expandvars(path: AnyStr) -> AnyStr: ...
@overload
def normcase(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def normcase(path: AnyStr) -> AnyStr: ...
@overload
def normpath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def normpath(path: AnyStr) -> AnyStr: ...
if sys.platform == 'win32':
@overload
def realpath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def realpath(path: AnyStr) -> AnyStr: ...
else:
@overload
def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def realpath(filename: AnyStr) -> AnyStr: ...
else:
def abspath(path: AnyStr) -> AnyStr: ...
def basename(path: AnyStr) -> AnyStr: ...
def dirname(path: AnyStr) -> AnyStr: ...
def expanduser(path: AnyStr) -> AnyStr: ...
def expandvars(path: AnyStr) -> AnyStr: ...
def normcase(path: AnyStr) -> AnyStr: ...
def normpath(path: AnyStr) -> AnyStr: ...
if sys.platform == 'win32':
def realpath(path: AnyStr) -> AnyStr: ...
else:
def realpath(filename: AnyStr) -> AnyStr: ...
if sys.version_info >= (3, 6):
# In reality it returns str for sequences of _StrPath and bytes for sequences
# of _BytesPath, but mypy does not accept such a signature.
def commonpath(paths: Sequence[_PathType]) -> Any: ...
elif sys.version_info >= (3, 5):
def commonpath(paths: Sequence[AnyStr]) -> AnyStr: ...
# NOTE: Empty lists results in '' (str) regardless of contained type.
# Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes
# So, fall back to Any
def commonprefix(list: Sequence[_PathType]) -> Any: ...
if sys.version_info >= (3, 3):
def exists(path: Union[_PathType, int]) -> bool: ...
else:
def exists(path: _PathType) -> bool: ...
def lexists(path: _PathType) -> bool: ...
# These return float if os.stat_float_times() == True,
# but int is a subclass of float.
def getatime(path: _PathType) -> float: ...
def getmtime(path: _PathType) -> float: ...
def getctime(path: _PathType) -> float: ...
def getsize(path: _PathType) -> int: ...
def isabs(path: _PathType) -> bool: ...
def isfile(path: _PathType) -> bool: ...
def isdir(path: _PathType) -> bool: ...
def islink(path: _PathType) -> bool: ...
def ismount(path: _PathType) -> bool: ...
if sys.version_info < (3, 0):
# Make sure signatures are disjunct, and allow combinations of bytes and unicode.
# (Since Python 2 allows that, too)
# Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in
# a type error.
@overload
def join(__p1: bytes, *p: bytes) -> bytes: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: Text, *p: _PathType) -> Text: ...
elif sys.version_info >= (3, 6):
# Mypy complains that the signatures overlap (same for relpath below), but things seem to behave correctly anyway.
@overload
def join(path: _StrPath, *paths: _StrPath) -> Text: ...
@overload
def join(path: _BytesPath, *paths: _BytesPath) -> bytes: ...
else:
def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ...
@overload
def relpath(path: _BytesPath, start: Optional[_BytesPath] = ...) -> bytes: ...
@overload
def relpath(path: _StrPath, start: Optional[_StrPath] = ...) -> Text: ...
def samefile(path1: _PathType, path2: _PathType) -> bool: ...
def sameopenfile(fp1: int, fp2: int) -> bool: ...
def samestat(stat1: os.stat_result, stat2: os.stat_result) -> bool: ...
if sys.version_info >= (3, 6):
@overload
def split(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitdrive(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitext(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
else:
def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
if sys.platform == 'win32':
def splitunc(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated
if sys.version_info < (3,):
def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ...
+201
View File
@@ -0,0 +1,201 @@
from typing import AnyStr, Dict, List, Mapping, Tuple, Union, Sequence, IO, Optional, TypeVar
error = OSError
confstr_names: Dict[str, int]
environ: Dict[str, str]
pathconf_names: Dict[str, int]
sysconf_names: Dict[str, int]
_T = TypeVar("_T")
EX_CANTCREAT: int
EX_CONFIG: int
EX_DATAERR: int
EX_IOERR: int
EX_NOHOST: int
EX_NOINPUT: int
EX_NOPERM: int
EX_NOUSER: int
EX_OK: int
EX_OSERR: int
EX_OSFILE: int
EX_PROTOCOL: int
EX_SOFTWARE: int
EX_TEMPFAIL: int
EX_UNAVAILABLE: int
EX_USAGE: int
F_OK: int
NGROUPS_MAX: int
O_APPEND: int
O_ASYNC: int
O_CREAT: int
O_DIRECT: int
O_DIRECTORY: int
O_DSYNC: int
O_EXCL: int
O_LARGEFILE: int
O_NDELAY: int
O_NOATIME: int
O_NOCTTY: int
O_NOFOLLOW: int
O_NONBLOCK: int
O_RDONLY: int
O_RDWR: int
O_RSYNC: int
O_SYNC: int
O_TRUNC: int
O_WRONLY: int
R_OK: int
TMP_MAX: int
WCONTINUED: int
WNOHANG: int
WUNTRACED: int
W_OK: int
X_OK: int
def WCOREDUMP(status: int) -> bool: ...
def WEXITSTATUS(status: int) -> bool: ...
def WIFCONTINUED(status: int) -> bool: ...
def WIFEXITED(status: int) -> bool: ...
def WIFSIGNALED(status: int) -> bool: ...
def WIFSTOPPED(status: int) -> bool: ...
def WSTOPSIG(status: int) -> bool: ...
def WTERMSIG(status: int) -> bool: ...
class stat_result(object):
n_fields: int
n_sequence_fields: int
n_unnamed_fields: int
st_mode: int
st_ino: int
st_dev: int
st_nlink: int
st_uid: int
st_gid: int
st_size: int
st_atime: int
st_mtime: int
st_ctime: int
class statvfs_result(object):
n_fields: int
n_sequence_fields: int
n_unnamed_fields: int
f_bsize: int
f_frsize: int
f_blocks: int
f_bfree: int
f_bavail: int
f_files: int
f_ffree: int
f_favail: int
f_flag: int
f_namemax: int
def _exit(status: int) -> None: ...
def abort() -> None: ...
def access(path: unicode, mode: int) -> bool: ...
def chdir(path: unicode) -> None: ...
def chmod(path: unicode, mode: int) -> None: ...
def chown(path: unicode, uid: int, gid: int) -> None: ...
def chroot(path: unicode) -> None: ...
def close(fd: int) -> None: ...
def closerange(fd_low: int, fd_high: int) -> None: ...
def confstr(name: Union[str, int]) -> str: ...
def ctermid() -> str: ...
def dup(fd: int) -> int: ...
def dup2(fd: int, fd2: int) -> None: ...
def execv(path: str, args: Sequence[str], env: Mapping[str, str]) -> None: ...
def execve(path: str, args: Sequence[str], env: Mapping[str, str]) -> None: ...
def fchdir(fd: int) -> None: ...
def fchmod(fd: int, mode: int) -> None: ...
def fchown(fd: int, uid: int, gid: int) -> None: ...
def fdatasync(fd: int) -> None: ...
def fdopen(fd: int, mode: str = ..., bufsize: int = ...) -> IO[str]: ...
def fork() -> int: ...
def forkpty() -> Tuple[int, int]: ...
def fpathconf(fd: int, name: str) -> None: ...
def fstat(fd: int) -> stat_result: ...
def fstatvfs(fd: int) -> statvfs_result: ...
def fsync(fd: int) -> None: ...
def ftruncate(fd: int, length: int) -> None: ...
def getcwd() -> str: ...
def getcwdu() -> unicode: ...
def getegid() -> int: ...
def geteuid() -> int: ...
def getgid() -> int: ...
def getgroups() -> List[int]: ...
def getloadavg() -> Tuple[float, float, float]: ...
def getlogin() -> str: ...
def getpgid(pid: int) -> int: ...
def getpgrp() -> int: ...
def getpid() -> int: ...
def getppid() -> int: ...
def getresgid() -> Tuple[int, int, int]: ...
def getresuid() -> Tuple[int, int, int]: ...
def getsid(pid: int) -> int: ...
def getuid() -> int: ...
def initgroups(username: str, gid: int) -> None: ...
def isatty(fd: int) -> bool: ...
def kill(pid: int, sig: int) -> None: ...
def killpg(pgid: int, sig: int) -> None: ...
def lchown(path: unicode, uid: int, gid: int) -> None: ...
def link(source: unicode, link_name: str) -> None: ...
def listdir(path: AnyStr) -> List[AnyStr]: ...
def lseek(fd: int, pos: int, how: int) -> None: ...
def lstat(path: unicode) -> stat_result: ...
def major(device: int) -> int: ...
def makedev(major: int, minor: int) -> int: ...
def minor(device: int) -> int: ...
def mkdir(path: unicode, mode: int = ...) -> None: ...
def mkfifo(path: unicode, mode: int = ...) -> None: ...
def mknod(filename: unicode, mode: int = ..., device: int = ...) -> None: ...
def nice(increment: int) -> int: ...
def open(file: unicode, flags: int, mode: int = ...) -> int: ...
def openpty() -> Tuple[int, int]: ...
def pathconf(path: unicode, name: str) -> str: ...
def pipe() -> Tuple[int, int]: ...
def popen(command: str, mode: str = ..., bufsize: int = ...) -> IO[str]: ...
def putenv(varname: str, value: str) -> None: ...
def read(fd: int, n: int) -> str: ...
def readlink(path: _T) -> _T: ...
def remove(path: unicode) -> None: ...
def rename(src: unicode, dst: unicode) -> None: ...
def rmdir(path: unicode) -> None: ...
def setegid(egid: int) -> None: ...
def seteuid(euid: int) -> None: ...
def setgid(gid: int) -> None: ...
def setgroups(groups: Sequence[int]) -> None: ...
def setpgid(pid: int, pgrp: int) -> None: ...
def setpgrp() -> None: ...
def setregid(rgid: int, egid: int) -> None: ...
def setresgid(rgid: int, egid: int, sgid: int) -> None: ...
def setresuid(ruid: int, euid: int, suid: int) -> None: ...
def setreuid(ruid: int, euid: int) -> None: ...
def setsid() -> None: ...
def setuid(pid: int) -> None: ...
def stat(path: unicode) -> stat_result: ...
def statvfs(path: unicode) -> statvfs_result: ...
def stat_float_times(fd: int) -> None: ...
def strerror(code: int) -> str: ...
def symlink(source: unicode, link_name: unicode) -> None: ...
def sysconf(name: Union[str, int]) -> int: ...
def system(command: unicode) -> int: ...
def tcgetpgrp(fd: int) -> int: ...
def tcsetpgrp(fd: int, pg: int) -> None: ...
def times() -> Tuple[float, float, float, float, float]: ...
def tmpfile() -> IO[str]: ...
def ttyname(fd: int) -> str: ...
def umask(mask: int) -> int: ...
def uname() -> Tuple[str, str, str, str, str]: ...
def unlink(path: unicode) -> None: ...
def unsetenv(varname: str) -> None: ...
def urandom(n: int) -> str: ...
def utime(path: unicode, times: Optional[Tuple[int, int]]) -> None: ...
def wait() -> int: ...
_r = Tuple[float, float, int, int, int, int, int, int, int, int, int, int, int, int, int, int]
def wait3(options: int) -> Tuple[int, int, _r]: ...
def wait4(pid: int, options: int) -> Tuple[int, int, _r]: ...
def waitpid(pid: int, options: int) -> int: ...
def write(fd: int, str: str) -> int: ...
@@ -0,0 +1,21 @@
from typing import Sequence, AnyStr, Text
import sys
if sys.version_info >= (3, 0):
def commonprefix(m: Sequence[str]) -> str: ...
else:
def commonprefix(m: Sequence[AnyStr]) -> AnyStr: ...
def exists(path: Text) -> bool: ...
def isfile(path: Text) -> bool: ...
def isdir(s: Text) -> bool: ...
def getsize(filename: Text) -> int: ...
def getmtime(filename: Text) -> float: ...
def getatime(filename: Text) -> float: ...
def getctime(filename: Text) -> float: ...
if sys.version_info >= (3, 4):
def samestat(s1: str, s2: str) -> int: ...
def samefile(f1: str, f2: str) -> int: ...
def sameopenfile(fp1: str, fp2: str) -> int: ...
@@ -0,0 +1,171 @@
# Stubs for os.path
# Ron Murawski <ron@horizonchess.com>
import os
import sys
from typing import overload, List, Any, AnyStr, Sequence, Tuple, TypeVar, Union, Text, Callable, Optional
if sys.version_info < (3, 8):
_T = TypeVar('_T')
if sys.version_info >= (3, 6):
from builtins import _PathLike
_PathType = Union[bytes, Text, _PathLike]
_StrPath = Union[Text, _PathLike[Text]]
_BytesPath = Union[bytes, _PathLike[bytes]]
else:
_PathType = Union[bytes, Text]
_StrPath = Text
_BytesPath = bytes
# ----- os.path variables -----
supports_unicode_filenames: bool
# aliases (also in os)
curdir: str
pardir: str
sep: str
altsep: Optional[str]
extsep: str
pathsep: str
defpath: str
devnull: str
# ----- os.path function stubs -----
if sys.version_info >= (3, 6):
# Overloads are necessary to work around python/mypy#3644.
@overload
def abspath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def abspath(path: AnyStr) -> AnyStr: ...
@overload
def basename(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def basename(path: AnyStr) -> AnyStr: ...
@overload
def dirname(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def dirname(path: AnyStr) -> AnyStr: ...
@overload
def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def expanduser(path: AnyStr) -> AnyStr: ...
@overload
def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def expandvars(path: AnyStr) -> AnyStr: ...
@overload
def normcase(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def normcase(path: AnyStr) -> AnyStr: ...
@overload
def normpath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def normpath(path: AnyStr) -> AnyStr: ...
if sys.platform == 'win32':
@overload
def realpath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def realpath(path: AnyStr) -> AnyStr: ...
else:
@overload
def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def realpath(filename: AnyStr) -> AnyStr: ...
else:
def abspath(path: AnyStr) -> AnyStr: ...
def basename(path: AnyStr) -> AnyStr: ...
def dirname(path: AnyStr) -> AnyStr: ...
def expanduser(path: AnyStr) -> AnyStr: ...
def expandvars(path: AnyStr) -> AnyStr: ...
def normcase(path: AnyStr) -> AnyStr: ...
def normpath(path: AnyStr) -> AnyStr: ...
if sys.platform == 'win32':
def realpath(path: AnyStr) -> AnyStr: ...
else:
def realpath(filename: AnyStr) -> AnyStr: ...
if sys.version_info >= (3, 6):
# In reality it returns str for sequences of _StrPath and bytes for sequences
# of _BytesPath, but mypy does not accept such a signature.
def commonpath(paths: Sequence[_PathType]) -> Any: ...
elif sys.version_info >= (3, 5):
def commonpath(paths: Sequence[AnyStr]) -> AnyStr: ...
# NOTE: Empty lists results in '' (str) regardless of contained type.
# Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes
# So, fall back to Any
def commonprefix(list: Sequence[_PathType]) -> Any: ...
if sys.version_info >= (3, 3):
def exists(path: Union[_PathType, int]) -> bool: ...
else:
def exists(path: _PathType) -> bool: ...
def lexists(path: _PathType) -> bool: ...
# These return float if os.stat_float_times() == True,
# but int is a subclass of float.
def getatime(path: _PathType) -> float: ...
def getmtime(path: _PathType) -> float: ...
def getctime(path: _PathType) -> float: ...
def getsize(path: _PathType) -> int: ...
def isabs(path: _PathType) -> bool: ...
def isfile(path: _PathType) -> bool: ...
def isdir(path: _PathType) -> bool: ...
def islink(path: _PathType) -> bool: ...
def ismount(path: _PathType) -> bool: ...
if sys.version_info < (3, 0):
# Make sure signatures are disjunct, and allow combinations of bytes and unicode.
# (Since Python 2 allows that, too)
# Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in
# a type error.
@overload
def join(__p1: bytes, *p: bytes) -> bytes: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: Text, *p: _PathType) -> Text: ...
elif sys.version_info >= (3, 6):
# Mypy complains that the signatures overlap (same for relpath below), but things seem to behave correctly anyway.
@overload
def join(path: _StrPath, *paths: _StrPath) -> Text: ...
@overload
def join(path: _BytesPath, *paths: _BytesPath) -> bytes: ...
else:
def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ...
@overload
def relpath(path: _BytesPath, start: Optional[_BytesPath] = ...) -> bytes: ...
@overload
def relpath(path: _StrPath, start: Optional[_StrPath] = ...) -> Text: ...
def samefile(path1: _PathType, path2: _PathType) -> bool: ...
def sameopenfile(fp1: int, fp2: int) -> bool: ...
def samestat(stat1: os.stat_result, stat2: os.stat_result) -> bool: ...
if sys.version_info >= (3, 6):
@overload
def split(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitdrive(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitext(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
else:
def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
if sys.version_info < (3,):
def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ...
@@ -0,0 +1,177 @@
# NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent!
# Stubs for os.path
# Ron Murawski <ron@horizonchess.com>
import os
import sys
from typing import overload, List, Any, AnyStr, Sequence, Tuple, TypeVar, Union, Text, Callable, Optional
_T = TypeVar('_T')
if sys.version_info >= (3, 6):
from builtins import _PathLike
_PathType = Union[bytes, Text, _PathLike]
_StrPath = Union[Text, _PathLike[Text]]
_BytesPath = Union[bytes, _PathLike[bytes]]
else:
_PathType = Union[bytes, Text]
_StrPath = Text
_BytesPath = bytes
# ----- os.path variables -----
supports_unicode_filenames: bool
# aliases (also in os)
curdir: str
pardir: str
sep: str
if sys.platform == 'win32':
altsep: str
else:
altsep: Optional[str]
extsep: str
pathsep: str
defpath: str
devnull: str
# ----- os.path function stubs -----
if sys.version_info >= (3, 6):
# Overloads are necessary to work around python/mypy#3644.
@overload
def abspath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def abspath(path: AnyStr) -> AnyStr: ...
@overload
def basename(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def basename(path: AnyStr) -> AnyStr: ...
@overload
def dirname(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def dirname(path: AnyStr) -> AnyStr: ...
@overload
def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def expanduser(path: AnyStr) -> AnyStr: ...
@overload
def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def expandvars(path: AnyStr) -> AnyStr: ...
@overload
def normcase(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def normcase(path: AnyStr) -> AnyStr: ...
@overload
def normpath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def normpath(path: AnyStr) -> AnyStr: ...
if sys.platform == 'win32':
@overload
def realpath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def realpath(path: AnyStr) -> AnyStr: ...
else:
@overload
def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def realpath(filename: AnyStr) -> AnyStr: ...
else:
def abspath(path: AnyStr) -> AnyStr: ...
def basename(path: AnyStr) -> AnyStr: ...
def dirname(path: AnyStr) -> AnyStr: ...
def expanduser(path: AnyStr) -> AnyStr: ...
def expandvars(path: AnyStr) -> AnyStr: ...
def normcase(path: AnyStr) -> AnyStr: ...
def normpath(path: AnyStr) -> AnyStr: ...
if sys.platform == 'win32':
def realpath(path: AnyStr) -> AnyStr: ...
else:
def realpath(filename: AnyStr) -> AnyStr: ...
if sys.version_info >= (3, 6):
# In reality it returns str for sequences of _StrPath and bytes for sequences
# of _BytesPath, but mypy does not accept such a signature.
def commonpath(paths: Sequence[_PathType]) -> Any: ...
elif sys.version_info >= (3, 5):
def commonpath(paths: Sequence[AnyStr]) -> AnyStr: ...
# NOTE: Empty lists results in '' (str) regardless of contained type.
# Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes
# So, fall back to Any
def commonprefix(list: Sequence[_PathType]) -> Any: ...
if sys.version_info >= (3, 3):
def exists(path: Union[_PathType, int]) -> bool: ...
else:
def exists(path: _PathType) -> bool: ...
def lexists(path: _PathType) -> bool: ...
# These return float if os.stat_float_times() == True,
# but int is a subclass of float.
def getatime(path: _PathType) -> float: ...
def getmtime(path: _PathType) -> float: ...
def getctime(path: _PathType) -> float: ...
def getsize(path: _PathType) -> int: ...
def isabs(path: _PathType) -> bool: ...
def isfile(path: _PathType) -> bool: ...
def isdir(path: _PathType) -> bool: ...
def islink(path: _PathType) -> bool: ...
def ismount(path: _PathType) -> bool: ...
if sys.version_info < (3, 0):
# Make sure signatures are disjunct, and allow combinations of bytes and unicode.
# (Since Python 2 allows that, too)
# Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in
# a type error.
@overload
def join(__p1: bytes, *p: bytes) -> bytes: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: Text, *p: _PathType) -> Text: ...
elif sys.version_info >= (3, 6):
# Mypy complains that the signatures overlap (same for relpath below), but things seem to behave correctly anyway.
@overload
def join(path: _StrPath, *paths: _StrPath) -> Text: ...
@overload
def join(path: _BytesPath, *paths: _BytesPath) -> bytes: ...
else:
def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ...
@overload
def relpath(path: _BytesPath, start: Optional[_BytesPath] = ...) -> bytes: ...
@overload
def relpath(path: _StrPath, start: Optional[_StrPath] = ...) -> Text: ...
def samefile(path1: _PathType, path2: _PathType) -> bool: ...
def sameopenfile(fp1: int, fp2: int) -> bool: ...
def samestat(stat1: os.stat_result, stat2: os.stat_result) -> bool: ...
if sys.version_info >= (3, 6):
@overload
def split(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitdrive(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitext(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
else:
def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
if sys.platform == 'win32':
def splitunc(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated
if sys.version_info < (3,):
def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ...
@@ -0,0 +1,177 @@
# NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent!
# Stubs for os.path
# Ron Murawski <ron@horizonchess.com>
import os
import sys
from typing import overload, List, Any, AnyStr, Sequence, Tuple, TypeVar, Union, Text, Callable, Optional
_T = TypeVar('_T')
if sys.version_info >= (3, 6):
from builtins import _PathLike
_PathType = Union[bytes, Text, _PathLike]
_StrPath = Union[Text, _PathLike[Text]]
_BytesPath = Union[bytes, _PathLike[bytes]]
else:
_PathType = Union[bytes, Text]
_StrPath = Text
_BytesPath = bytes
# ----- os.path variables -----
supports_unicode_filenames: bool
# aliases (also in os)
curdir: str
pardir: str
sep: str
if sys.platform == 'win32':
altsep: str
else:
altsep: Optional[str]
extsep: str
pathsep: str
defpath: str
devnull: str
# ----- os.path function stubs -----
if sys.version_info >= (3, 6):
# Overloads are necessary to work around python/mypy#3644.
@overload
def abspath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def abspath(path: AnyStr) -> AnyStr: ...
@overload
def basename(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def basename(path: AnyStr) -> AnyStr: ...
@overload
def dirname(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def dirname(path: AnyStr) -> AnyStr: ...
@overload
def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def expanduser(path: AnyStr) -> AnyStr: ...
@overload
def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def expandvars(path: AnyStr) -> AnyStr: ...
@overload
def normcase(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def normcase(path: AnyStr) -> AnyStr: ...
@overload
def normpath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def normpath(path: AnyStr) -> AnyStr: ...
if sys.platform == 'win32':
@overload
def realpath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def realpath(path: AnyStr) -> AnyStr: ...
else:
@overload
def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def realpath(filename: AnyStr) -> AnyStr: ...
else:
def abspath(path: AnyStr) -> AnyStr: ...
def basename(path: AnyStr) -> AnyStr: ...
def dirname(path: AnyStr) -> AnyStr: ...
def expanduser(path: AnyStr) -> AnyStr: ...
def expandvars(path: AnyStr) -> AnyStr: ...
def normcase(path: AnyStr) -> AnyStr: ...
def normpath(path: AnyStr) -> AnyStr: ...
if sys.platform == 'win32':
def realpath(path: AnyStr) -> AnyStr: ...
else:
def realpath(filename: AnyStr) -> AnyStr: ...
if sys.version_info >= (3, 6):
# In reality it returns str for sequences of _StrPath and bytes for sequences
# of _BytesPath, but mypy does not accept such a signature.
def commonpath(paths: Sequence[_PathType]) -> Any: ...
elif sys.version_info >= (3, 5):
def commonpath(paths: Sequence[AnyStr]) -> AnyStr: ...
# NOTE: Empty lists results in '' (str) regardless of contained type.
# Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes
# So, fall back to Any
def commonprefix(list: Sequence[_PathType]) -> Any: ...
if sys.version_info >= (3, 3):
def exists(path: Union[_PathType, int]) -> bool: ...
else:
def exists(path: _PathType) -> bool: ...
def lexists(path: _PathType) -> bool: ...
# These return float if os.stat_float_times() == True,
# but int is a subclass of float.
def getatime(path: _PathType) -> float: ...
def getmtime(path: _PathType) -> float: ...
def getctime(path: _PathType) -> float: ...
def getsize(path: _PathType) -> int: ...
def isabs(path: _PathType) -> bool: ...
def isfile(path: _PathType) -> bool: ...
def isdir(path: _PathType) -> bool: ...
def islink(path: _PathType) -> bool: ...
def ismount(path: _PathType) -> bool: ...
if sys.version_info < (3, 0):
# Make sure signatures are disjunct, and allow combinations of bytes and unicode.
# (Since Python 2 allows that, too)
# Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in
# a type error.
@overload
def join(__p1: bytes, *p: bytes) -> bytes: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: Text, *p: _PathType) -> Text: ...
elif sys.version_info >= (3, 6):
# Mypy complains that the signatures overlap (same for relpath below), but things seem to behave correctly anyway.
@overload
def join(path: _StrPath, *paths: _StrPath) -> Text: ...
@overload
def join(path: _BytesPath, *paths: _BytesPath) -> bytes: ...
else:
def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ...
@overload
def relpath(path: _BytesPath, start: Optional[_BytesPath] = ...) -> bytes: ...
@overload
def relpath(path: _StrPath, start: Optional[_StrPath] = ...) -> Text: ...
def samefile(path1: _PathType, path2: _PathType) -> bool: ...
def sameopenfile(fp1: int, fp2: int) -> bool: ...
def samestat(stat1: os.stat_result, stat2: os.stat_result) -> bool: ...
if sys.version_info >= (3, 6):
@overload
def split(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitdrive(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitext(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
else:
def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
if sys.platform == 'win32':
def splitunc(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated
if sys.version_info < (3,):
def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ...
@@ -0,0 +1,663 @@
# Stubs for os
# Ron Murawski <ron@horizonchess.com>
from io import TextIOWrapper as _TextIOWrapper
from posix import listdir as listdir, times_result
import sys
from typing import (
Mapping, MutableMapping, Dict, List, Any, Tuple, Iterable, Iterator, NoReturn, overload, Union, AnyStr,
Optional, Generic, Set, Callable, Text, Sequence, NamedTuple, TypeVar, ContextManager
)
# Re-exported names from other modules.
from builtins import OSError as error
from . import path as path
_T = TypeVar('_T')
# ----- os variables -----
supports_bytes_environ: bool
supports_dir_fd: Set[Callable[..., Any]]
supports_fd: Set[Callable[..., Any]]
supports_effective_ids: Set[Callable[..., Any]]
supports_follow_symlinks: Set[Callable[..., Any]]
if sys.platform != 'win32':
# Unix only
PRIO_PROCESS: int
PRIO_PGRP: int
PRIO_USER: int
F_LOCK: int
F_TLOCK: int
F_ULOCK: int
F_TEST: int
POSIX_FADV_NORMAL: int
POSIX_FADV_SEQUENTIAL: int
POSIX_FADV_RANDOM: int
POSIX_FADV_NOREUSE: int
POSIX_FADV_WILLNEED: int
POSIX_FADV_DONTNEED: int
SF_NODISKIO: int
SF_MNOWAIT: int
SF_SYNC: int
XATTR_SIZE_MAX: int # Linux only
XATTR_CREATE: int # Linux only
XATTR_REPLACE: int # Linux only
P_PID: int
P_PGID: int
P_ALL: int
WEXITED: int
WSTOPPED: int
WNOWAIT: int
CLD_EXITED: int
CLD_DUMPED: int
CLD_TRAPPED: int
CLD_CONTINUED: int
SCHED_OTHER: int # some flavors of Unix
SCHED_BATCH: int # some flavors of Unix
SCHED_IDLE: int # some flavors of Unix
SCHED_SPORADIC: int # some flavors of Unix
SCHED_FIFO: int # some flavors of Unix
SCHED_RR: int # some flavors of Unix
SCHED_RESET_ON_FORK: int # some flavors of Unix
RTLD_LAZY: int
RTLD_NOW: int
RTLD_GLOBAL: int
RTLD_LOCAL: int
RTLD_NODELETE: int
RTLD_NOLOAD: int
RTLD_DEEPBIND: int
SEEK_SET: int
SEEK_CUR: int
SEEK_END: int
if sys.platform != 'win32':
SEEK_DATA: int # some flavors of Unix
SEEK_HOLE: int # some flavors of Unix
O_RDONLY: int
O_WRONLY: int
O_RDWR: int
O_APPEND: int
O_CREAT: int
O_EXCL: int
O_TRUNC: int
# We don't use sys.platform for O_* flags to denote platform-dependent APIs because some codes,
# including tests for mypy, use a more finer way than sys.platform before using these APIs
# See https://github.com/python/typeshed/pull/2286 for discussions
O_DSYNC: int # Unix only
O_RSYNC: int # Unix only
O_SYNC: int # Unix only
O_NDELAY: int # Unix only
O_NONBLOCK: int # Unix only
O_NOCTTY: int # Unix only
O_CLOEXEC: int # Unix only
O_SHLOCK: int # Unix only
O_EXLOCK: int # Unix only
O_BINARY: int # Windows only
O_NOINHERIT: int # Windows only
O_SHORT_LIVED: int # Windows only
O_TEMPORARY: int # Windows only
O_RANDOM: int # Windows only
O_SEQUENTIAL: int # Windows only
O_TEXT: int # Windows only
O_ASYNC: int # Gnu extension if in C library
O_DIRECT: int # Gnu extension if in C library
O_DIRECTORY: int # Gnu extension if in C library
O_NOFOLLOW: int # Gnu extension if in C library
O_NOATIME: int # Gnu extension if in C library
O_PATH: int # Gnu extension if in C library
O_TMPFILE: int # Gnu extension if in C library
O_LARGEFILE: int # Gnu extension if in C library
curdir: str
pardir: str
sep: str
if sys.platform == 'win32':
altsep: str
else:
altsep: Optional[str]
extsep: str
pathsep: str
defpath: str
linesep: str
devnull: str
name: str
F_OK: int
R_OK: int
W_OK: int
X_OK: int
class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]):
def copy(self) -> Dict[AnyStr, AnyStr]: ...
def __delitem__(self, key: AnyStr) -> None: ...
def __getitem__(self, key: AnyStr) -> AnyStr: ...
def __setitem__(self, key: AnyStr, value: AnyStr) -> None: ...
def __iter__(self) -> Iterator[AnyStr]: ...
def __len__(self) -> int: ...
environ: _Environ[str]
environb: _Environ[bytes]
if sys.platform != 'win32':
confstr_names: Dict[str, int]
pathconf_names: Dict[str, int]
sysconf_names: Dict[str, int]
EX_OK: int
EX_USAGE: int
EX_DATAERR: int
EX_NOINPUT: int
EX_NOUSER: int
EX_NOHOST: int
EX_UNAVAILABLE: int
EX_SOFTWARE: int
EX_OSERR: int
EX_OSFILE: int
EX_CANTCREAT: int
EX_IOERR: int
EX_TEMPFAIL: int
EX_PROTOCOL: int
EX_NOPERM: int
EX_CONFIG: int
EX_NOTFOUND: int
P_NOWAIT: int
P_NOWAITO: int
P_WAIT: int
if sys.platform == 'win32':
P_DETACH: int
P_OVERLAY: int
# wait()/waitpid() options
if sys.platform != 'win32':
WNOHANG: int # Unix only
WCONTINUED: int # some Unix systems
WUNTRACED: int # Unix only
TMP_MAX: int # Undocumented, but used by tempfile
# ----- os classes (structures) -----
class stat_result:
# For backward compatibility, the return value of stat() is also
# accessible as a tuple of at least 10 integers giving the most important
# (and portable) members of the stat structure, in the order st_mode,
# st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime,
# st_ctime. More items may be added at the end by some implementations.
st_mode: int # protection bits,
st_ino: int # inode number,
st_dev: int # device,
st_nlink: int # number of hard links,
st_uid: int # user id of owner,
st_gid: int # group id of owner,
st_size: int # size of file, in bytes,
st_atime: float # time of most recent access,
st_mtime: float # time of most recent content modification,
st_ctime: float # platform dependent (time of most recent metadata change on Unix, or the time of creation on Windows)
st_atime_ns: int # time of most recent access, in nanoseconds
st_mtime_ns: int # time of most recent content modification in nanoseconds
st_ctime_ns: int # platform dependent (time of most recent metadata change on Unix, or the time of creation on Windows) in nanoseconds
if sys.version_info >= (3, 8) and sys.platform == "win32":
st_reparse_tag: int
def __getitem__(self, i: int) -> int: ...
# not documented
def __init__(self, tuple: Tuple[int, ...]) -> None: ...
# On some Unix systems (such as Linux), the following attributes may also
# be available:
st_blocks: int # number of blocks allocated for file
st_blksize: int # filesystem blocksize
st_rdev: int # type of device if an inode device
st_flags: int # user defined flags for file
# On other Unix systems (such as FreeBSD), the following attributes may be
# available (but may be only filled out if root tries to use them):
st_gen: int # file generation number
st_birthtime: int # time of file creation
# On Mac OS systems, the following attributes may also be available:
st_rsize: int
st_creator: int
st_type: int
if sys.version_info >= (3, 6):
from builtins import _PathLike as PathLike # See comment in builtins
_PathType = path._PathType
_FdOrPathType = Union[int, _PathType]
if sys.version_info >= (3, 6):
class DirEntry(PathLike[AnyStr]):
# This is what the scandir interator yields
# The constructor is hidden
name: AnyStr
path: AnyStr
def inode(self) -> int: ...
def is_dir(self, *, follow_symlinks: bool = ...) -> bool: ...
def is_file(self, *, follow_symlinks: bool = ...) -> bool: ...
def is_symlink(self) -> bool: ...
def stat(self, *, follow_symlinks: bool = ...) -> stat_result: ...
def __fspath__(self) -> AnyStr: ...
else:
class DirEntry(Generic[AnyStr]):
# This is what the scandir interator yields
# The constructor is hidden
name: AnyStr
path: AnyStr
def inode(self) -> int: ...
def is_dir(self, *, follow_symlinks: bool = ...) -> bool: ...
def is_file(self, *, follow_symlinks: bool = ...) -> bool: ...
def is_symlink(self) -> bool: ...
def stat(self, *, follow_symlinks: bool = ...) -> stat_result: ...
if sys.platform != 'win32':
class statvfs_result: # Unix only
f_bsize: int
f_frsize: int
f_blocks: int
f_bfree: int
f_bavail: int
f_files: int
f_ffree: int
f_favail: int
f_flag: int
f_namemax: int
# ----- os function stubs -----
if sys.version_info >= (3, 6):
def fsencode(filename: Union[str, bytes, PathLike[Any]]) -> bytes: ...
else:
def fsencode(filename: Union[str, bytes]) -> bytes: ...
if sys.version_info >= (3, 6):
def fsdecode(filename: Union[str, bytes, PathLike[Any]]) -> str: ...
else:
def fsdecode(filename: Union[str, bytes]) -> str: ...
if sys.version_info >= (3, 6):
@overload
def fspath(path: str) -> str: ...
@overload
def fspath(path: bytes) -> bytes: ...
@overload
def fspath(path: PathLike[Any]) -> Any: ...
def get_exec_path(env: Optional[Mapping[str, str]] = ...) -> List[str]: ...
# NOTE: get_exec_path(): returns List[bytes] when env not None
def getlogin() -> str: ...
def getpid() -> int: ...
def getppid() -> int: ...
def strerror(code: int) -> str: ...
def umask(mask: int) -> int: ...
if sys.platform != 'win32':
# Unix only
def ctermid() -> str: ...
def getegid() -> int: ...
def geteuid() -> int: ...
def getgid() -> int: ...
def getgrouplist(user: str, gid: int) -> List[int]: ...
def getgroups() -> List[int]: ... # Unix only, behaves differently on Mac
def initgroups(username: str, gid: int) -> None: ...
def getpgid(pid: int) -> int: ...
def getpgrp() -> int: ...
def getpriority(which: int, who: int) -> int: ...
def setpriority(which: int, who: int, priority: int) -> None: ...
def getresuid() -> Tuple[int, int, int]: ...
def getresgid() -> Tuple[int, int, int]: ...
def getuid() -> int: ...
def setegid(egid: int) -> None: ...
def seteuid(euid: int) -> None: ...
def setgid(gid: int) -> None: ...
def setgroups(groups: Sequence[int]) -> None: ...
def setpgrp() -> None: ...
def setpgid(pid: int, pgrp: int) -> None: ...
def setregid(rgid: int, egid: int) -> None: ...
def setresgid(rgid: int, egid: int, sgid: int) -> None: ...
def setresuid(ruid: int, euid: int, suid: int) -> None: ...
def setreuid(ruid: int, euid: int) -> None: ...
def getsid(pid: int) -> int: ...
def setsid() -> None: ...
def setuid(uid: int) -> None: ...
from posix import uname_result
def uname() -> uname_result: ...
@overload
def getenv(key: Text) -> Optional[str]: ...
@overload
def getenv(key: Text, default: _T) -> Union[str, _T]: ...
def getenvb(key: bytes, default: bytes = ...) -> bytes: ...
def putenv(key: Union[bytes, Text], value: Union[bytes, Text]) -> None: ...
def unsetenv(key: Union[bytes, Text]) -> None: ...
# Return IO or TextIO
def fdopen(fd: int, mode: str = ..., buffering: int = ..., encoding: Optional[str] = ...,
errors: str = ..., newline: str = ..., closefd: bool = ...) -> Any: ...
def close(fd: int) -> None: ...
def closerange(fd_low: int, fd_high: int) -> None: ...
def device_encoding(fd: int) -> Optional[str]: ...
def dup(fd: int) -> int: ...
if sys.version_info >= (3, 7):
def dup2(fd: int, fd2: int, inheritable: bool = ...) -> int: ...
else:
def dup2(fd: int, fd2: int, inheritable: bool = ...) -> None: ...
def fstat(fd: int) -> stat_result: ...
def fsync(fd: int) -> None: ...
def lseek(fd: int, pos: int, how: int) -> int: ...
def open(file: _PathType, flags: int, mode: int = ..., *, dir_fd: Optional[int] = ...) -> int: ...
def pipe() -> Tuple[int, int]: ...
def read(fd: int, n: int) -> bytes: ...
if sys.platform != 'win32':
# Unix only
def fchmod(fd: int, mode: int) -> None: ...
def fchown(fd: int, uid: int, gid: int) -> None: ...
def fdatasync(fd: int) -> None: ... # Unix only, not Mac
def fpathconf(fd: int, name: Union[str, int]) -> int: ...
def fstatvfs(fd: int) -> statvfs_result: ...
def ftruncate(fd: int, length: int) -> None: ...
def get_blocking(fd: int) -> bool: ...
def set_blocking(fd: int, blocking: bool) -> None: ...
def isatty(fd: int) -> bool: ...
def lockf(__fd: int, __cmd: int, __length: int) -> None: ...
def openpty() -> Tuple[int, int]: ... # some flavors of Unix
def pipe2(flags: int) -> Tuple[int, int]: ... # some flavors of Unix
def posix_fallocate(fd: int, offset: int, length: int) -> None: ...
def posix_fadvise(fd: int, offset: int, length: int, advice: int) -> None: ...
def pread(fd: int, buffersize: int, offset: int) -> bytes: ...
def pwrite(fd: int, string: bytes, offset: int) -> int: ...
@overload
def sendfile(__out_fd: int, __in_fd: int, offset: Optional[int], count: int) -> int: ...
@overload
def sendfile(__out_fd: int, __in_fd: int, offset: int, count: int,
headers: Sequence[bytes] = ..., trailers: Sequence[bytes] = ..., flags: int = ...) -> int: ... # FreeBSD and Mac OS X only
def readv(fd: int, buffers: Sequence[bytearray]) -> int: ...
def writev(fd: int, buffers: Sequence[bytes]) -> int: ...
terminal_size = NamedTuple('terminal_size', [('columns', int), ('lines', int)])
def get_terminal_size(fd: int = ...) -> terminal_size: ...
def get_inheritable(fd: int) -> bool: ...
def set_inheritable(fd: int, inheritable: bool) -> None: ...
if sys.platform != 'win32':
# Unix only
def tcgetpgrp(fd: int) -> int: ...
def tcsetpgrp(fd: int, pg: int) -> None: ...
def ttyname(fd: int) -> str: ...
def write(fd: int, string: bytes) -> int: ...
def access(
path: _FdOrPathType,
mode: int,
*,
dir_fd: Optional[int] = ...,
effective_ids: bool = ...,
follow_symlinks: bool = ...,
) -> bool: ...
def chdir(path: _FdOrPathType) -> None: ...
def fchdir(fd: int) -> None: ...
def getcwd() -> str: ...
def getcwdb() -> bytes: ...
def chmod(path: _FdOrPathType, mode: int, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> None: ...
if sys.platform != 'win32':
def chflags(path: _PathType, flags: int, follow_symlinks: bool = ...) -> None: ... # some flavors of Unix
def chown(path: _FdOrPathType, uid: int, gid: int, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> None: ... # Unix only
if sys.platform != 'win32':
# Unix only
def chroot(path: _PathType) -> None: ...
def lchflags(path: _PathType, flags: int) -> None: ...
def lchmod(path: _PathType, mode: int) -> None: ...
def lchown(path: _PathType, uid: int, gid: int) -> None: ...
def link(
src: _PathType,
link_name: _PathType,
*,
src_dir_fd: Optional[int] = ...,
dst_dir_fd: Optional[int] = ...,
follow_symlinks: bool = ...,
) -> None: ...
def lstat(path: _PathType, *, dir_fd: Optional[int] = ...) -> stat_result: ...
def mkdir(path: _PathType, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ...
if sys.platform != 'win32':
def mkfifo(path: _PathType, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ... # Unix only
def makedirs(name: _PathType, mode: int = ..., exist_ok: bool = ...) -> None: ...
def mknod(path: _PathType, mode: int = ..., device: int = ..., *, dir_fd: Optional[int] = ...) -> None: ...
def major(device: int) -> int: ...
def minor(device: int) -> int: ...
def makedev(major: int, minor: int) -> int: ...
if sys.platform != 'win32':
def pathconf(path: _FdOrPathType, name: Union[str, int]) -> int: ... # Unix only
if sys.version_info >= (3, 6):
def readlink(path: Union[AnyStr, PathLike[AnyStr]], *, dir_fd: Optional[int] = ...) -> AnyStr: ...
else:
def readlink(path: AnyStr, *, dir_fd: Optional[int] = ...) -> AnyStr: ...
def remove(path: _PathType, *, dir_fd: Optional[int] = ...) -> None: ...
def removedirs(name: _PathType) -> None: ...
def rename(src: _PathType, dst: _PathType, *, src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...) -> None: ...
def renames(old: _PathType, new: _PathType) -> None: ...
def replace(src: _PathType, dst: _PathType, *, src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...) -> None: ...
def rmdir(path: _PathType, *, dir_fd: Optional[int] = ...) -> None: ...
if sys.version_info >= (3, 7):
class _ScandirIterator(Iterator[DirEntry[AnyStr]], ContextManager[_ScandirIterator[AnyStr]]):
def __next__(self) -> DirEntry[AnyStr]: ...
def close(self) -> None: ...
@overload
def scandir() -> _ScandirIterator[str]: ...
@overload
def scandir(path: int) -> _ScandirIterator[str]: ...
@overload
def scandir(path: Union[AnyStr, PathLike[AnyStr]]) -> _ScandirIterator[AnyStr]: ...
elif sys.version_info >= (3, 6):
class _ScandirIterator(Iterator[DirEntry[AnyStr]], ContextManager[_ScandirIterator[AnyStr]]):
def __next__(self) -> DirEntry[AnyStr]: ...
def close(self) -> None: ...
@overload
def scandir() -> _ScandirIterator[str]: ...
@overload
def scandir(path: Union[AnyStr, PathLike[AnyStr]]) -> _ScandirIterator[AnyStr]: ...
else:
@overload
def scandir() -> Iterator[DirEntry[str]]: ...
@overload
def scandir(path: AnyStr) -> Iterator[DirEntry[AnyStr]]: ...
def stat(path: _FdOrPathType, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> stat_result: ...
if sys.version_info < (3, 7):
@overload
def stat_float_times() -> bool: ...
@overload
def stat_float_times(__newvalue: bool) -> None: ...
if sys.platform != 'win32':
def statvfs(path: _FdOrPathType) -> statvfs_result: ... # Unix only
def symlink(
source: _PathType,
link_name: _PathType,
target_is_directory: bool = ...,
*,
dir_fd: Optional[int] = ...,
) -> None: ...
if sys.platform != 'win32':
def sync() -> None: ... # Unix only
def truncate(path: _FdOrPathType, length: int) -> None: ... # Unix only up to version 3.4
def unlink(path: _PathType, *, dir_fd: Optional[int] = ...) -> None: ...
def utime(
path: _FdOrPathType,
times: Optional[Union[Tuple[int, int], Tuple[float, float]]] = ...,
*,
ns: Tuple[int, int] = ...,
dir_fd: Optional[int] = ...,
follow_symlinks: bool = ...,
) -> None: ...
_OnError = Callable[[OSError], Any]
if sys.version_info >= (3, 6):
def walk(top: Union[AnyStr, PathLike[AnyStr]], topdown: bool = ...,
onerror: Optional[_OnError] = ...,
followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr],
List[AnyStr]]]: ...
else:
def walk(top: AnyStr, topdown: bool = ..., onerror: Optional[_OnError] = ...,
followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr],
List[AnyStr]]]: ...
if sys.platform != 'win32':
if sys.version_info >= (3, 7):
@overload
def fwalk(top: Union[str, PathLike[str]] = ..., topdown: bool = ...,
onerror: Optional[_OnError] = ..., *, follow_symlinks: bool = ...,
dir_fd: Optional[int] = ...) -> Iterator[Tuple[str, List[str], List[str], int]]: ...
@overload
def fwalk(top: bytes, topdown: bool = ...,
onerror: Optional[_OnError] = ..., *, follow_symlinks: bool = ...,
dir_fd: Optional[int] = ...) -> Iterator[Tuple[bytes, List[bytes], List[bytes], int]]: ...
elif sys.version_info >= (3, 6):
def fwalk(top: Union[str, PathLike[str]] = ..., topdown: bool = ...,
onerror: Optional[_OnError] = ..., *, follow_symlinks: bool = ...,
dir_fd: Optional[int] = ...) -> Iterator[Tuple[str, List[str], List[str], int]]: ...
else:
def fwalk(top: str = ..., topdown: bool = ...,
onerror: Optional[_OnError] = ..., *, follow_symlinks: bool = ...,
dir_fd: Optional[int] = ...) -> Iterator[Tuple[str, List[str], List[str], int]]: ...
def getxattr(path: _FdOrPathType, attribute: _PathType, *, follow_symlinks: bool = ...) -> bytes: ... # Linux only
def listxattr(path: _FdOrPathType, *, follow_symlinks: bool = ...) -> List[str]: ... # Linux only
def removexattr(path: _FdOrPathType, attribute: _PathType, *, follow_symlinks: bool = ...) -> None: ... # Linux only
def setxattr(path: _FdOrPathType, attribute: _PathType, value: bytes, flags: int = ..., *,
follow_symlinks: bool = ...) -> None: ... # Linux only
def abort() -> NoReturn: ...
# These are defined as execl(file, *args) but the first *arg is mandatory.
def execl(file: _PathType, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ...
def execlp(file: _PathType, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ...
# These are: execle(file, *args, env) but env is pulled from the last element of the args.
def execle(file: _PathType, __arg0: Union[bytes, Text], *args: Any) -> NoReturn: ...
def execlpe(file: _PathType, __arg0: Union[bytes, Text], *args: Any) -> NoReturn: ...
# The docs say `args: tuple or list of strings`
# The implementation enforces tuple or list so we can't use Sequence.
_ExecVArgs = Union[Tuple[Union[bytes, Text], ...], List[bytes], List[Text], List[Union[bytes, Text]]]
def execv(path: _PathType, args: _ExecVArgs) -> NoReturn: ...
def execve(path: _FdOrPathType, args: _ExecVArgs, env: Mapping[str, str]) -> NoReturn: ...
def execvp(file: _PathType, args: _ExecVArgs) -> NoReturn: ...
def execvpe(file: _PathType, args: _ExecVArgs, env: Mapping[str, str]) -> NoReturn: ...
def _exit(n: int) -> NoReturn: ...
def kill(pid: int, sig: int) -> None: ...
if sys.platform != 'win32':
# Unix only
def fork() -> int: ...
def forkpty() -> Tuple[int, int]: ... # some flavors of Unix
def killpg(pgid: int, sig: int) -> None: ...
def nice(increment: int) -> int: ...
def plock(op: int) -> None: ... # ???op is int?
class _wrap_close(_TextIOWrapper):
def close(self) -> Optional[int]: ... # type: ignore
def popen(command: str, mode: str = ..., buffering: int = ...) -> _wrap_close: ...
def spawnl(mode: int, path: _PathType, arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> int: ...
def spawnle(mode: int, path: _PathType, arg0: Union[bytes, Text],
*args: Any) -> int: ... # Imprecise sig
def spawnv(mode: int, path: _PathType, args: List[Union[bytes, Text]]) -> int: ...
def spawnve(mode: int, path: _PathType, args: List[Union[bytes, Text]],
env: Mapping[str, str]) -> int: ...
def system(command: _PathType) -> int: ...
def times() -> times_result: ...
def waitpid(pid: int, options: int) -> Tuple[int, int]: ...
if sys.platform == 'win32':
def startfile(path: _PathType, operation: Optional[str] = ...) -> None: ...
else:
# Unix only
def spawnlp(mode: int, file: _PathType, arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> int: ...
def spawnlpe(mode: int, file: _PathType, arg0: Union[bytes, Text], *args: Any) -> int: ... # Imprecise signature
def spawnvp(mode: int, file: _PathType, args: List[Union[bytes, Text]]) -> int: ...
def spawnvpe(mode: int, file: _PathType, args: List[Union[bytes, Text]], env: Mapping[str, str]) -> int: ...
def wait() -> Tuple[int, int]: ... # Unix only
from posix import waitid_result
def waitid(idtype: int, ident: int, options: int) -> waitid_result: ...
def wait3(options: int) -> Tuple[int, int, Any]: ...
def wait4(pid: int, options: int) -> Tuple[int, int, Any]: ...
def WCOREDUMP(status: int) -> bool: ...
def WIFCONTINUED(status: int) -> bool: ...
def WIFSTOPPED(status: int) -> bool: ...
def WIFSIGNALED(status: int) -> bool: ...
def WIFEXITED(status: int) -> bool: ...
def WEXITSTATUS(status: int) -> int: ...
def WSTOPSIG(status: int) -> int: ...
def WTERMSIG(status: int) -> int: ...
if sys.platform != 'win32':
from posix import sched_param
def sched_get_priority_min(policy: int) -> int: ... # some flavors of Unix
def sched_get_priority_max(policy: int) -> int: ... # some flavors of Unix
def sched_setscheduler(pid: int, policy: int, param: sched_param) -> None: ... # some flavors of Unix
def sched_getscheduler(pid: int) -> int: ... # some flavors of Unix
def sched_setparam(pid: int, param: sched_param) -> None: ... # some flavors of Unix
def sched_getparam(pid: int) -> sched_param: ... # some flavors of Unix
def sched_rr_get_interval(pid: int) -> float: ... # some flavors of Unix
def sched_yield() -> None: ... # some flavors of Unix
def sched_setaffinity(pid: int, mask: Iterable[int]) -> None: ... # some flavors of Unix
def sched_getaffinity(pid: int) -> Set[int]: ... # some flavors of Unix
def cpu_count() -> Optional[int]: ...
if sys.platform != 'win32':
# Unix only
def confstr(name: Union[str, int]) -> Optional[str]: ...
def getloadavg() -> Tuple[float, float, float]: ...
def sysconf(name: Union[str, int]) -> int: ...
if sys.version_info >= (3, 6):
def getrandom(size: int, flags: int = ...) -> bytes: ...
def urandom(size: int) -> bytes: ...
else:
def urandom(n: int) -> bytes: ...
if sys.version_info >= (3, 7):
def register_at_fork(func: Callable[..., object], when: str) -> None: ...
if sys.version_info >= (3, 8):
if sys.platform == "win32":
class _AddedDllDirectory:
path: Optional[str]
def close(self) -> None: ...
def __enter__(self: _T) -> _T: ...
def __exit__(self, *args: Any) -> None: ...
def add_dll_directory(path: str) -> _AddedDllDirectory: ...
if sys.platform == "linux":
MFD_CLOEXEC: int
MFD_ALLOW_SEALING: int
MFD_HUGETLB: int
MFD_HUGE_SHIFT: int
MFD_HUGE_MASK: int
MFD_HUGE_64KB: int
MFD_HUGE_512KB: int
MFD_HUGE_1MB: int
MFD_HUGE_2MB: int
MFD_HUGE_8MB: int
MFD_HUGE_16MB: int
MFD_HUGE_32MB: int
MFD_HUGE_256MB: int
MFD_HUGE_512MB: int
MFD_HUGE_1GB: int
MFD_HUGE_2GB: int
MFD_HUGE_16GB: int
def memfd_create(name: str, flags: int = ...) -> int: ...
@@ -0,0 +1,177 @@
# NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent!
# Stubs for os.path
# Ron Murawski <ron@horizonchess.com>
import os
import sys
from typing import overload, List, Any, AnyStr, Sequence, Tuple, TypeVar, Union, Text, Callable, Optional
_T = TypeVar('_T')
if sys.version_info >= (3, 6):
from builtins import _PathLike
_PathType = Union[bytes, Text, _PathLike]
_StrPath = Union[Text, _PathLike[Text]]
_BytesPath = Union[bytes, _PathLike[bytes]]
else:
_PathType = Union[bytes, Text]
_StrPath = Text
_BytesPath = bytes
# ----- os.path variables -----
supports_unicode_filenames: bool
# aliases (also in os)
curdir: str
pardir: str
sep: str
if sys.platform == 'win32':
altsep: str
else:
altsep: Optional[str]
extsep: str
pathsep: str
defpath: str
devnull: str
# ----- os.path function stubs -----
if sys.version_info >= (3, 6):
# Overloads are necessary to work around python/mypy#3644.
@overload
def abspath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def abspath(path: AnyStr) -> AnyStr: ...
@overload
def basename(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def basename(path: AnyStr) -> AnyStr: ...
@overload
def dirname(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def dirname(path: AnyStr) -> AnyStr: ...
@overload
def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def expanduser(path: AnyStr) -> AnyStr: ...
@overload
def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def expandvars(path: AnyStr) -> AnyStr: ...
@overload
def normcase(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def normcase(path: AnyStr) -> AnyStr: ...
@overload
def normpath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def normpath(path: AnyStr) -> AnyStr: ...
if sys.platform == 'win32':
@overload
def realpath(path: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def realpath(path: AnyStr) -> AnyStr: ...
else:
@overload
def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ...
@overload
def realpath(filename: AnyStr) -> AnyStr: ...
else:
def abspath(path: AnyStr) -> AnyStr: ...
def basename(path: AnyStr) -> AnyStr: ...
def dirname(path: AnyStr) -> AnyStr: ...
def expanduser(path: AnyStr) -> AnyStr: ...
def expandvars(path: AnyStr) -> AnyStr: ...
def normcase(path: AnyStr) -> AnyStr: ...
def normpath(path: AnyStr) -> AnyStr: ...
if sys.platform == 'win32':
def realpath(path: AnyStr) -> AnyStr: ...
else:
def realpath(filename: AnyStr) -> AnyStr: ...
if sys.version_info >= (3, 6):
# In reality it returns str for sequences of _StrPath and bytes for sequences
# of _BytesPath, but mypy does not accept such a signature.
def commonpath(paths: Sequence[_PathType]) -> Any: ...
elif sys.version_info >= (3, 5):
def commonpath(paths: Sequence[AnyStr]) -> AnyStr: ...
# NOTE: Empty lists results in '' (str) regardless of contained type.
# Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes
# So, fall back to Any
def commonprefix(list: Sequence[_PathType]) -> Any: ...
if sys.version_info >= (3, 3):
def exists(path: Union[_PathType, int]) -> bool: ...
else:
def exists(path: _PathType) -> bool: ...
def lexists(path: _PathType) -> bool: ...
# These return float if os.stat_float_times() == True,
# but int is a subclass of float.
def getatime(path: _PathType) -> float: ...
def getmtime(path: _PathType) -> float: ...
def getctime(path: _PathType) -> float: ...
def getsize(path: _PathType) -> int: ...
def isabs(path: _PathType) -> bool: ...
def isfile(path: _PathType) -> bool: ...
def isdir(path: _PathType) -> bool: ...
def islink(path: _PathType) -> bool: ...
def ismount(path: _PathType) -> bool: ...
if sys.version_info < (3, 0):
# Make sure signatures are disjunct, and allow combinations of bytes and unicode.
# (Since Python 2 allows that, too)
# Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in
# a type error.
@overload
def join(__p1: bytes, *p: bytes) -> bytes: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ...
@overload
def join(__p1: Text, *p: _PathType) -> Text: ...
elif sys.version_info >= (3, 6):
# Mypy complains that the signatures overlap (same for relpath below), but things seem to behave correctly anyway.
@overload
def join(path: _StrPath, *paths: _StrPath) -> Text: ...
@overload
def join(path: _BytesPath, *paths: _BytesPath) -> bytes: ...
else:
def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ...
@overload
def relpath(path: _BytesPath, start: Optional[_BytesPath] = ...) -> bytes: ...
@overload
def relpath(path: _StrPath, start: Optional[_StrPath] = ...) -> Text: ...
def samefile(path1: _PathType, path2: _PathType) -> bool: ...
def sameopenfile(fp1: int, fp2: int) -> bool: ...
def samestat(stat1: os.stat_result, stat2: os.stat_result) -> bool: ...
if sys.version_info >= (3, 6):
@overload
def split(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitdrive(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitext(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
else:
def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
if sys.platform == 'win32':
def splitunc(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated
if sys.version_info < (3,):
def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ...
+131
View File
@@ -0,0 +1,131 @@
# Stubs for posix
# NOTE: These are incomplete!
import sys
from typing import List, NamedTuple, Optional, overload
from os import stat_result as stat_result
if sys.version_info >= (3, 6):
from builtins import _PathLike # See comment in builtins
uname_result = NamedTuple('uname_result', [
('sysname', str),
('nodename', str),
('release', str),
('version', str),
('machine', str),
])
times_result = NamedTuple('times_result', [
('user', float),
('system', float),
('children_user', float),
('children_system', float),
('elapsed', float),
])
waitid_result = NamedTuple('waitid_result', [
('si_pid', int),
('si_uid', int),
('si_signo', int),
('si_status', int),
('si_code', int),
])
sched_param = NamedTuple('sched_param', [
('sched_priority', int),
])
EX_CANTCREAT: int
EX_CONFIG: int
EX_DATAERR: int
EX_IOERR: int
EX_NOHOST: int
EX_NOINPUT: int
EX_NOPERM: int
EX_NOTFOUND: int
EX_NOUSER: int
EX_OK: int
EX_OSERR: int
EX_OSFILE: int
EX_PROTOCOL: int
EX_SOFTWARE: int
EX_TEMPFAIL: int
EX_UNAVAILABLE: int
EX_USAGE: int
F_OK: int
R_OK: int
W_OK: int
X_OK: int
if sys.version_info >= (3, 6):
GRND_NONBLOCK: int
GRND_RANDOM: int
NGROUPS_MAX: int
O_APPEND: int
O_ACCMODE: int
O_ASYNC: int
O_CREAT: int
O_DIRECT: int
O_DIRECTORY: int
O_DSYNC: int
O_EXCL: int
O_LARGEFILE: int
O_NDELAY: int
O_NOATIME: int
O_NOCTTY: int
O_NOFOLLOW: int
O_NONBLOCK: int
O_RDONLY: int
O_RDWR: int
O_RSYNC: int
O_SYNC: int
O_TRUNC: int
O_WRONLY: int
ST_APPEND: int
ST_MANDLOCK: int
ST_NOATIME: int
ST_NODEV: int
ST_NODIRATIME: int
ST_NOEXEC: int
ST_NOSUID: int
ST_RDONLY: int
ST_RELATIME: int
ST_SYNCHRONOUS: int
ST_WRITE: int
TMP_MAX: int
WCONTINUED: int
WCOREDUMP: int
WEXITSTATUS: int
WIFCONTINUED: int
WIFEXITED: int
WIFSIGNALED: int
WIFSTOPPED: int
WNOHANG: int
WSTOPSIG: int
WTERMSIG: int
WUNTRACED: int
if sys.version_info >= (3, 6):
@overload
def listdir(path: Optional[str] = ...) -> List[str]: ...
@overload
def listdir(path: bytes) -> List[bytes]: ...
@overload
def listdir(path: int) -> List[str]: ...
@overload
def listdir(path: _PathLike[str]) -> List[str]: ...
else:
@overload
def listdir(path: Optional[str] = ...) -> List[str]: ...
@overload
def listdir(path: bytes) -> List[bytes]: ...
@overload
def listdir(path: int) -> List[str]: ...
@@ -158,6 +158,7 @@ public class PyNames {
public static final String ABC_SET = "Set";
public static final String ABC_MUTABLE_SET = "MutableSet";
public static final String PATH_LIKE = "PathLike";
public static final String BUILTIN_PATH_LIKE = "_PathLike";
public static final String AWAITABLE = "Awaitable";
public static final String ASYNC_ITERABLE = "AsyncIterable";
@@ -1441,17 +1441,6 @@ public class PyTypingTypeProvider extends PyTypeProviderBase {
continue;
}
}
if (isBuiltinPathLike(element)) {
// see https://github.com/python/typeshed/commit/41561f11c7b06368aebe512acf69d8010662266d
// or comment in typeshed/stdlib/3/builtins.pyi near _PathLike class
final QualifiedName osPathLikeQName = QualifiedName.fromComponents("os", PyNames.PATH_LIKE);
final PsiElement osPathLike =
PyResolveImportUtil.resolveTopLevelMember(osPathLikeQName, PyResolveImportUtil.fromFoothold(element));
if (osPathLike != null) {
elements.add(Pair.create(null, osPathLike));
continue;
}
}
if (element != null) {
elements.add(Pair.create(null, element));
}
@@ -1473,12 +1462,6 @@ public class PyTypingTypeProvider extends PyTypeProviderBase {
return Collections.singletonList(expression);
}
private static boolean isBuiltinPathLike(@Nullable PsiElement element) {
return element instanceof PyClass &&
PyBuiltinCache.getInstance(element).isBuiltin(element) &&
("_" + PyNames.PATH_LIKE).equals(((PyClass)element).getName());
}
@NotNull
public static Collection<String> resolveToQualifiedNames(@NotNull PyExpression expression, @NotNull TypeEvalContext context) {
final Set<String> names = Sets.newLinkedHashSet();
@@ -72,12 +72,12 @@ public class PyTypeModelBuilder {
}
}
static class CollectionOf extends TypeModel {
private final String collectionName;
private static class CollectionOf extends TypeModel {
private final TypeModel collectionType;
private final List<TypeModel> elementTypes;
private CollectionOf(String collectionName, List<TypeModel> elementTypes) {
this.collectionName = collectionName;
private CollectionOf(TypeModel collectionType, List<TypeModel> elementTypes) {
this.collectionType = collectionType;
this.elementTypes = elementTypes;
}
@@ -270,14 +270,14 @@ public class PyTypeModelBuilder {
result = new TupleType(elementModels, tupleType.isHomogeneous());
}
else if (type instanceof PyCollectionType) {
final String name = type.getName();
final List<PyType> elementTypes = ((PyCollectionType)type).getElementTypes();
final PyCollectionType asCollection = (PyCollectionType)type;
final List<TypeModel> elementModels = new ArrayList<>();
for (PyType elementType : elementTypes) {
for (PyType elementType : asCollection.getElementTypes()) {
elementModels.add(build(elementType, true));
}
if (!elementModels.isEmpty()) {
result = new CollectionOf(name, elementModels);
final TypeModel collectionType = build(new PyClassTypeImpl(asCollection.getPyClass(), asCollection.isDefinition()), false);
result = new CollectionOf(collectionType, elementModels);
}
}
else if (type instanceof PyUnionType && allowUnions) {
@@ -304,6 +304,9 @@ public class PyTypeModelBuilder {
else if (type instanceof PyGenericType) {
result = new GenericType(type.getName());
}
else if (type != null && type.isBuiltin() && PyNames.BUILTIN_PATH_LIKE.equals(type.getName())) {
result = new NamedType(PyNames.PATH_LIKE);
}
if (result == null) {
result = NamedType.nameOrAny(type);
}
@@ -483,6 +486,7 @@ public class PyTypeModelBuilder {
private abstract static class TypeNameVisitor implements TypeVisitor {
private int myDepth = 0;
private final static int MAX_DEPTH = 6;
private boolean switchBuiltinToTyping = false;
@Override
public void oneOf(OneOf oneOf) {
@@ -522,7 +526,7 @@ public class PyTypeModelBuilder {
}
final boolean allTypeParamsAreAny = ContainerUtil.and(collectionOf.elementTypes, t -> t == NamedType.ANY);
if (allTypeParamsAreAny) {
name(collectionOf.collectionName);
collectionOf.collectionType.accept(this);
}
else {
typingGenericFormat(collectionOf);
@@ -531,8 +535,11 @@ public class PyTypeModelBuilder {
}
protected void typingGenericFormat(CollectionOf collectionOf) {
final String name = collectionOf.collectionName;
addType(PyTypingTypeProvider.TYPING_COLLECTION_CLASSES.getOrDefault(name, name));
final boolean prevSwitchBuiltinToTyping = switchBuiltinToTyping;
switchBuiltinToTyping = true;
collectionOf.collectionType.accept(this);
switchBuiltinToTyping = prevSwitchBuiltinToTyping;
if (!collectionOf.elementTypes.isEmpty()) {
add("[");
processList(collectionOf.elementTypes);
@@ -544,7 +551,7 @@ public class PyTypeModelBuilder {
@Override
public void name(String name) {
addType(name);
addType(switchBuiltinToTyping ? PyTypingTypeProvider.TYPING_COLLECTION_CLASSES.getOrDefault(name, name) : name);
}
@Override
@@ -100,7 +100,7 @@ public class PyABCUtil {
if (PyNames.AWAITABLE.equals(superClassName)) {
return hasMethod(subClass, PyNames.DUNDER_AWAIT, inherited, context);
}
if (PyNames.PATH_LIKE.equals(superClassName)) {
if (PyNames.BUILTIN_PATH_LIKE.equals(superClassName)) {
return hasMethod(subClass, PyNames.FSPATH, inherited, context);
}
return false;
@@ -854,17 +854,6 @@ public class PythonCompletionTest extends PyTestCase {
assertSameElements(suggested, "VAR", "subpkg1");
}
// PY-14519
public void testOsPath() {
myFixture.copyDirectoryToProject(getTestName(true), "");
myFixture.configureByFile("a.py");
myFixture.completeBasic();
final List<String> suggested = myFixture.getLookupElementStrings();
assertNotNull(suggested);
assertContainsElements(suggested, "path");
}
// PY-14331
public void testExcludedTopLevelPackage() {
myFixture.copyDirectoryToProject(getTestName(true), "");
@@ -714,7 +714,6 @@
<typeProvider implementation="com.jetbrains.python.codeInsight.stdlib.PyDataclassTypeProvider"/>
<typeProvider implementation="com.jetbrains.python.codeInsight.stdlib.PyNamedTupleTypeProvider"/>
<typeProvider implementation="com.jetbrains.python.codeInsight.stdlib.PyNamedTupleOverridingTypeProvider"/>
<pyModuleMembersProvider implementation="com.jetbrains.python.codeInsight.stdlib.PyStdlibModuleMembersProvider"/>
<pyModuleMembersProvider implementation="com.jetbrains.python.codeInsight.stdlib.PyStdlibOverridingModuleMembersProvider"/>
<documentationLinkProvider implementation="com.jetbrains.python.codeInsight.stdlib.PyStdlibDocumentationLinkProvider"/>
<canonicalPathProvider implementation="com.jetbrains.python.codeInsight.stdlib.PyStdlibCanonicalPathProvider"/>
@@ -1,32 +0,0 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.codeInsight.stdlib;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.QualifiedName;
import com.jetbrains.python.codeInsight.PyCustomMember;
import com.jetbrains.python.psi.PyFile;
import com.jetbrains.python.psi.resolve.ResolveImportUtil;
import com.jetbrains.python.psi.types.PyModuleMembersProvider;
import com.jetbrains.python.psi.types.TypeEvalContext;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Collections;
/**
* @author yole
*/
public class PyStdlibModuleMembersProvider extends PyModuleMembersProvider {
@Override
@NotNull
protected Collection<PyCustomMember> getMembersByQName(@NotNull PyFile module, @NotNull String qName, @NotNull TypeEvalContext context) {
if (qName.equals("os")) {
final String pathModuleName = SystemInfo.isWindows ? "ntpath" : "posixpath";
final PsiElement path = ResolveImportUtil.resolveModuleInRoots(QualifiedName.fromDottedString(pathModuleName), module);
return Collections.singletonList(new PyCustomMember("path", path));
}
return Collections.emptyList();
}
}
@@ -28,7 +28,7 @@ import static com.jetbrains.python.psi.PyUtil.as;
public class PyStdlibTypeProvider extends PyTypeProviderBase {
@NotNull
private static final Set<String> OPEN_FUNCTIONS = ImmutableSet.of("os.fdopen", "posix.fdopen", "nt.fdopen");
private static final Set<String> OPEN_FUNCTIONS = ImmutableSet.of("os.fdopen", "posix.fdopen");
@Nullable
public static PyStdlibTypeProvider getInstance() {
@@ -1,151 +0,0 @@
"""
Path operations common to more than one OS
Do not use directly. The OS specific modules import the appropriate
functions from this module themselves.
"""
import os
import stat
__all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime',
'getsize', 'isdir', 'isfile', 'samefile', 'sameopenfile',
'samestat']
# Does a path exist?
# This is false for dangling symbolic links on systems that support them.
def exists(path):
"""Test whether a path exists. Returns False for broken symbolic links"""
try:
os.stat(path)
except OSError:
return False
return True
# This follows symbolic links, so both islink() and isdir() can be true
# for the same path on systems that support symlinks
def isfile(path):
"""Test whether a path is a regular file"""
try:
st = os.stat(path)
except OSError:
return False
return stat.S_ISREG(st.st_mode)
# Is a path a directory?
# This follows symbolic links, so both islink() and isdir()
# can be true for the same path on systems that support symlinks
def isdir(s):
"""Return true if the pathname refers to an existing directory."""
try:
st = os.stat(s)
except OSError:
return False
return stat.S_ISDIR(st.st_mode)
def getsize(filename):
"""Return the size of a file, reported by os.stat()."""
return os.stat(filename).st_size
def getmtime(filename):
"""Return the last modification time of a file, reported by os.stat()."""
return os.stat(filename).st_mtime
def getatime(filename):
"""Return the last access time of a file, reported by os.stat()."""
return os.stat(filename).st_atime
def getctime(filename):
"""Return the metadata change time of a file, reported by os.stat()."""
return os.stat(filename).st_ctime
# Return the longest prefix of all list elements.
def commonprefix(m):
"Given a list of pathnames, returns the longest common leading component"
if not m: return ''
# Some people pass in a list of pathname parts to operate in an OS-agnostic
# fashion; don't try to translate in that case as that's an abuse of the
# API and they are already doing what they need to be OS-agnostic and so
# they most likely won't be using an os.PathLike object in the sublists.
if not isinstance(m[0], (list, tuple)):
m = tuple(map(os.fspath, m))
s1 = min(m)
s2 = max(m)
for i, c in enumerate(s1):
if c != s2[i]:
return s1[:i]
return s1
# Are two stat buffers (obtained from stat, fstat or lstat)
# describing the same file?
def samestat(s1, s2):
"""Test whether two stat buffers reference the same file"""
return (s1.st_ino == s2.st_ino and
s1.st_dev == s2.st_dev)
# Are two filenames really pointing to the same file?
def samefile(f1, f2):
"""Test whether two pathnames reference the same actual file"""
s1 = os.stat(f1)
s2 = os.stat(f2)
return samestat(s1, s2)
# Are two open files really referencing the same file?
# (Not necessarily the same file descriptor!)
def sameopenfile(fp1, fp2):
"""Test whether two open file objects reference the same file"""
s1 = os.fstat(fp1)
s2 = os.fstat(fp2)
return samestat(s1, s2)
# Split a path in root and extension.
# The extension is everything starting at the last dot in the last
# pathname component; the root is everything before that.
# It is always true that root + ext == p.
# Generic implementation of splitext, to be parametrized with
# the separators
def _splitext(p, sep, altsep, extsep):
"""Split the extension from a pathname.
Extension is everything from the last dot to the end, ignoring
leading dots. Returns "(root, ext)"; ext may be empty."""
# NOTE: This code must work for text and bytes strings.
sepIndex = p.rfind(sep)
if altsep:
altsepIndex = p.rfind(altsep)
sepIndex = max(sepIndex, altsepIndex)
dotIndex = p.rfind(extsep)
if dotIndex > sepIndex:
# skip all leading dots
filenameIndex = sepIndex + 1
while filenameIndex < dotIndex:
if p[filenameIndex:filenameIndex+1] != extsep:
return p[:dotIndex], p[dotIndex:]
filenameIndex += 1
return p, p[:0]
def _check_arg_types(funcname, *args):
hasstr = hasbytes = False
for s in args:
if isinstance(s, str):
hasstr = True
elif isinstance(s, bytes):
hasbytes = True
else:
raise TypeError('%s() argument must be str or bytes, not %r' %
(funcname, s.__class__.__name__)) from None
if hasstr and hasbytes:
raise TypeError("Can't mix strings and bytes in path components") from None
-669
View File
@@ -1,669 +0,0 @@
# Module 'ntpath' -- common operations on WinNT/Win95 pathnames
"""Common pathname manipulations, WindowsNT/95 version.
Instead of importing this module directly, import os and refer to this
module as os.path.
"""
# strings representing various path-related bits and pieces
# These are primarily for export; internally, they are hardcoded.
# Should be set before imports for resolving cyclic dependency.
curdir = '.'
pardir = '..'
extsep = '.'
sep = '\\'
pathsep = ';'
altsep = '/'
defpath = '.;C:\\bin'
devnull = 'nul'
import os
import sys
import stat
import genericpath
from genericpath import *
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
"basename","dirname","commonprefix","getsize","getmtime",
"getatime","getctime", "islink","exists","lexists","isdir","isfile",
"ismount", "expanduser","expandvars","normpath","abspath",
"curdir","pardir","sep","pathsep","defpath","altsep",
"extsep","devnull","realpath","supports_unicode_filenames","relpath",
"samefile", "sameopenfile", "samestat", "commonpath"]
def _get_bothseps(path):
if isinstance(path, bytes):
return b'\\/'
else:
return '\\/'
# Normalize the case of a pathname and map slashes to backslashes.
# Other normalizations (such as optimizing '../' away) are not done
# (this is done by normpath).
def normcase(s):
"""Normalize case of pathname.
Makes all characters lowercase and all slashes into backslashes."""
s = os.fspath(s)
try:
if isinstance(s, bytes):
return s.replace(b'/', b'\\').lower()
else:
return s.replace('/', '\\').lower()
except (TypeError, AttributeError):
if not isinstance(s, (bytes, str)):
raise TypeError("normcase() argument must be str or bytes, "
"not %r" % s.__class__.__name__) from None
raise
# Return whether a path is absolute.
# Trivial in Posix, harder on Windows.
# For Windows it is absolute if it starts with a slash or backslash (current
# volume), or if a pathname after the volume-letter-and-colon or UNC-resource
# starts with a slash or backslash.
def isabs(s):
"""Test whether a path is absolute"""
s = os.fspath(s)
s = splitdrive(s)[1]
return len(s) > 0 and s[0] in _get_bothseps(s)
# Join two (or more) paths.
def join(path, *paths):
path = os.fspath(path)
if isinstance(path, bytes):
sep = b'\\'
seps = b'\\/'
colon = b':'
else:
sep = '\\'
seps = '\\/'
colon = ':'
try:
if not paths:
path[:0] + sep #23780: Ensure compatible data type even if p is null.
result_drive, result_path = splitdrive(path)
for p in map(os.fspath, paths):
p_drive, p_path = splitdrive(p)
if p_path and p_path[0] in seps:
# Second path is absolute
if p_drive or not result_drive:
result_drive = p_drive
result_path = p_path
continue
elif p_drive and p_drive != result_drive:
if p_drive.lower() != result_drive.lower():
# Different drives => ignore the first path entirely
result_drive = p_drive
result_path = p_path
continue
# Same drive in different case
result_drive = p_drive
# Second path is relative to the first
if result_path and result_path[-1] not in seps:
result_path = result_path + sep
result_path = result_path + p_path
## add separator between UNC and non-absolute path
if (result_path and result_path[0] not in seps and
result_drive and result_drive[-1:] != colon):
return result_drive + sep + result_path
return result_drive + result_path
except (TypeError, AttributeError, BytesWarning):
genericpath._check_arg_types('join', path, *paths)
raise
# Split a path in a drive specification (a drive letter followed by a
# colon) and the path specification.
# It is always true that drivespec + pathspec == p
def splitdrive(p):
"""Split a pathname into drive/UNC sharepoint and relative path specifiers.
Returns a 2-tuple (drive_or_unc, path); either part may be empty.
If you assign
result = splitdrive(p)
It is always true that:
result[0] + result[1] == p
If the path contained a drive letter, drive_or_unc will contain everything
up to and including the colon. e.g. splitdrive("c:/dir") returns ("c:", "/dir")
If the path contained a UNC path, the drive_or_unc will contain the host name
and share up to but not including the fourth directory separator character.
e.g. splitdrive("//host/computer/dir") returns ("//host/computer", "/dir")
Paths cannot contain both a drive letter and a UNC path.
"""
p = os.fspath(p)
if len(p) >= 2:
if isinstance(p, bytes):
sep = b'\\'
altsep = b'/'
colon = b':'
else:
sep = '\\'
altsep = '/'
colon = ':'
normp = p.replace(altsep, sep)
if (normp[0:2] == sep*2) and (normp[2:3] != sep):
# is a UNC path:
# vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
# \\machine\mountpoint\directory\etc\...
# directory ^^^^^^^^^^^^^^^
index = normp.find(sep, 2)
if index == -1:
return p[:0], p
index2 = normp.find(sep, index + 1)
# a UNC path can't have two slashes in a row
# (after the initial two)
if index2 == index + 1:
return p[:0], p
if index2 == -1:
index2 = len(p)
return p[:index2], p[index2:]
if normp[1:2] == colon:
return p[:2], p[2:]
return p[:0], p
# Split a path in head (everything up to the last '/') and tail (the
# rest). After the trailing '/' is stripped, the invariant
# join(head, tail) == p holds.
# The resulting head won't end in '/' unless it is the root.
def split(p):
"""Split a pathname.
Return tuple (head, tail) where tail is everything after the final slash.
Either part may be empty."""
p = os.fspath(p)
seps = _get_bothseps(p)
d, p = splitdrive(p)
# set i to index beyond p's last slash
i = len(p)
while i and p[i-1] not in seps:
i -= 1
head, tail = p[:i], p[i:] # now tail has no slashes
# remove trailing slashes from head, unless it's all slashes
head = head.rstrip(seps) or head
return d + head, tail
# Split a path in root and extension.
# The extension is everything starting at the last dot in the last
# pathname component; the root is everything before that.
# It is always true that root + ext == p.
def splitext(p):
p = os.fspath(p)
if isinstance(p, bytes):
return genericpath._splitext(p, b'\\', b'/', b'.')
else:
return genericpath._splitext(p, '\\', '/', '.')
splitext.__doc__ = genericpath._splitext.__doc__
# Return the tail (basename) part of a path.
def basename(p):
"""Returns the final component of a pathname"""
return split(p)[1]
# Return the head (dirname) part of a path.
def dirname(p):
"""Returns the directory component of a pathname"""
return split(p)[0]
# Is a path a symbolic link?
# This will always return false on systems where os.lstat doesn't exist.
def islink(path):
"""Test whether a path is a symbolic link.
This will always return false for Windows prior to 6.0.
"""
try:
st = os.lstat(path)
except (OSError, AttributeError):
return False
return stat.S_ISLNK(st.st_mode)
# Being true for dangling symbolic links is also useful.
def lexists(path):
"""Test whether a path exists. Returns True for broken symbolic links"""
try:
st = os.lstat(path)
except OSError:
return False
return True
# Is a path a mount point?
# Any drive letter root (eg c:\)
# Any share UNC (eg \\server\share)
# Any volume mounted on a filesystem folder
#
# No one method detects all three situations. Historically we've lexically
# detected drive letter roots and share UNCs. The canonical approach to
# detecting mounted volumes (querying the reparse tag) fails for the most
# common case: drive letter roots. The alternative which uses GetVolumePathName
# fails if the drive letter is the result of a SUBST.
try:
from nt import _getvolumepathname
except ImportError:
_getvolumepathname = None
def ismount(path):
"""Test whether a path is a mount point (a drive root, the root of a
share, or a mounted volume)"""
path = os.fspath(path)
seps = _get_bothseps(path)
path = abspath(path)
root, rest = splitdrive(path)
if root and root[0] in seps:
return (not rest) or (rest in seps)
if rest in seps:
return True
if _getvolumepathname:
return path.rstrip(seps) == _getvolumepathname(path).rstrip(seps)
else:
return False
# Expand paths beginning with '~' or '~user'.
# '~' means $HOME; '~user' means that user's home directory.
# If the path doesn't begin with '~', or if the user or $HOME is unknown,
# the path is returned unchanged (leaving error reporting to whatever
# function is called with the expanded path as argument).
# See also module 'glob' for expansion of *, ? and [...] in pathnames.
# (A function should also be defined to do full *sh-style environment
# variable expansion.)
def expanduser(path):
"""Expand ~ and ~user constructs.
If user or $HOME is unknown, do nothing."""
path = os.fspath(path)
if isinstance(path, bytes):
tilde = b'~'
else:
tilde = '~'
if not path.startswith(tilde):
return path
i, n = 1, len(path)
while i < n and path[i] not in _get_bothseps(path):
i += 1
if 'HOME' in os.environ:
userhome = os.environ['HOME']
elif 'USERPROFILE' in os.environ:
userhome = os.environ['USERPROFILE']
elif not 'HOMEPATH' in os.environ:
return path
else:
try:
drive = os.environ['HOMEDRIVE']
except KeyError:
drive = ''
userhome = join(drive, os.environ['HOMEPATH'])
if isinstance(path, bytes):
userhome = os.fsencode(userhome)
if i != 1: #~user
userhome = join(dirname(userhome), path[1:i])
return userhome + path[i:]
# Expand paths containing shell variable substitutions.
# The following rules apply:
# - no expansion within single quotes
# - '$$' is translated into '$'
# - '%%' is translated into '%' if '%%' are not seen in %var1%%var2%
# - ${varname} is accepted.
# - $varname is accepted.
# - %varname% is accepted.
# - varnames can be made out of letters, digits and the characters '_-'
# (though is not verified in the ${varname} and %varname% cases)
# XXX With COMMAND.COM you can use any characters in a variable name,
# XXX except '^|<>='.
def expandvars(path):
"""Expand shell variables of the forms $var, ${var} and %var%.
Unknown variables are left unchanged."""
path = os.fspath(path)
if isinstance(path, bytes):
if b'$' not in path and b'%' not in path:
return path
import string
varchars = bytes(string.ascii_letters + string.digits + '_-', 'ascii')
quote = b'\''
percent = b'%'
brace = b'{'
rbrace = b'}'
dollar = b'$'
environ = getattr(os, 'environb', None)
else:
if '$' not in path and '%' not in path:
return path
import string
varchars = string.ascii_letters + string.digits + '_-'
quote = '\''
percent = '%'
brace = '{'
rbrace = '}'
dollar = '$'
environ = os.environ
res = path[:0]
index = 0
pathlen = len(path)
while index < pathlen:
c = path[index:index+1]
if c == quote: # no expansion within single quotes
path = path[index + 1:]
pathlen = len(path)
try:
index = path.index(c)
res += c + path[:index + 1]
except ValueError:
res += c + path
index = pathlen - 1
elif c == percent: # variable or '%'
if path[index + 1:index + 2] == percent:
res += c
index += 1
else:
path = path[index+1:]
pathlen = len(path)
try:
index = path.index(percent)
except ValueError:
res += percent + path
index = pathlen - 1
else:
var = path[:index]
try:
if environ is None:
value = os.fsencode(os.environ[os.fsdecode(var)])
else:
value = environ[var]
except KeyError:
value = percent + var + percent
res += value
elif c == dollar: # variable or '$$'
if path[index + 1:index + 2] == dollar:
res += c
index += 1
elif path[index + 1:index + 2] == brace:
path = path[index+2:]
pathlen = len(path)
try:
index = path.index(rbrace)
except ValueError:
res += dollar + brace + path
index = pathlen - 1
else:
var = path[:index]
try:
if environ is None:
value = os.fsencode(os.environ[os.fsdecode(var)])
else:
value = environ[var]
except KeyError:
value = dollar + brace + var + rbrace
res += value
else:
var = path[:0]
index += 1
c = path[index:index + 1]
while c and c in varchars:
var += c
index += 1
c = path[index:index + 1]
try:
if environ is None:
value = os.fsencode(os.environ[os.fsdecode(var)])
else:
value = environ[var]
except KeyError:
value = dollar + var
res += value
if c:
index -= 1
else:
res += c
index += 1
return res
# Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A\B.
# Previously, this function also truncated pathnames to 8+3 format,
# but as this module is called "ntpath", that's obviously wrong!
def normpath(path):
"""Normalize path, eliminating double slashes, etc."""
path = os.fspath(path)
if isinstance(path, bytes):
sep = b'\\'
altsep = b'/'
curdir = b'.'
pardir = b'..'
special_prefixes = (b'\\\\.\\', b'\\\\?\\')
else:
sep = '\\'
altsep = '/'
curdir = '.'
pardir = '..'
special_prefixes = ('\\\\.\\', '\\\\?\\')
if path.startswith(special_prefixes):
# in the case of paths with these prefixes:
# \\.\ -> device names
# \\?\ -> literal paths
# do not do any normalization, but return the path unchanged
return path
path = path.replace(altsep, sep)
prefix, path = splitdrive(path)
# collapse initial backslashes
if path.startswith(sep):
prefix += sep
path = path.lstrip(sep)
comps = path.split(sep)
i = 0
while i < len(comps):
if not comps[i] or comps[i] == curdir:
del comps[i]
elif comps[i] == pardir:
if i > 0 and comps[i-1] != pardir:
del comps[i-1:i+1]
i -= 1
elif i == 0 and prefix.endswith(sep):
del comps[i]
else:
i += 1
else:
i += 1
# If the path is now empty, substitute '.'
if not prefix and not comps:
comps.append(curdir)
return prefix + sep.join(comps)
def _abspath_fallback(path):
"""Return the absolute version of a path as a fallback function in case
`nt._getfullpathname` is not available or raises OSError. See bpo-31047 for
more.
"""
path = os.fspath(path)
if not isabs(path):
if isinstance(path, bytes):
cwd = os.getcwdb()
else:
cwd = os.getcwd()
path = join(cwd, path)
return normpath(path)
# Return an absolute path.
try:
from nt import _getfullpathname
except ImportError: # not running on Windows - mock up something sensible
abspath = _abspath_fallback
else: # use native Windows method on Windows
def abspath(path):
"""Return the absolute version of a path."""
try:
return _getfullpathname(path)
except OSError:
return _abspath_fallback(path)
# realpath is a no-op on systems without islink support
realpath = abspath
# Win9x family and earlier have no Unicode filename support.
supports_unicode_filenames = (hasattr(sys, "getwindowsversion") and
sys.getwindowsversion()[3] >= 2)
def relpath(path, start=None):
"""Return a relative version of a path"""
path = os.fspath(path)
if isinstance(path, bytes):
sep = b'\\'
curdir = b'.'
pardir = b'..'
else:
sep = '\\'
curdir = '.'
pardir = '..'
if start is None:
start = curdir
if not path:
raise ValueError("no path specified")
start = os.fspath(start)
try:
start_abs = abspath(normpath(start))
path_abs = abspath(normpath(path))
start_drive, start_rest = splitdrive(start_abs)
path_drive, path_rest = splitdrive(path_abs)
if normcase(start_drive) != normcase(path_drive):
raise ValueError("path is on mount %r, start on mount %r" % (
path_drive, start_drive))
start_list = [x for x in start_rest.split(sep) if x]
path_list = [x for x in path_rest.split(sep) if x]
# Work out how much of the filepath is shared by start and path.
i = 0
for e1, e2 in zip(start_list, path_list):
if normcase(e1) != normcase(e2):
break
i += 1
rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
if not rel_list:
return curdir
return join(*rel_list)
except (TypeError, ValueError, AttributeError, BytesWarning, DeprecationWarning):
genericpath._check_arg_types('relpath', path, start)
raise
# Return the longest common sub-path of the sequence of paths given as input.
# The function is case-insensitive and 'separator-insensitive', i.e. if the
# only difference between two paths is the use of '\' versus '/' as separator,
# they are deemed to be equal.
#
# However, the returned path will have the standard '\' separator (even if the
# given paths had the alternative '/' separator) and will have the case of the
# first path given in the sequence. Additionally, any trailing separator is
# stripped from the returned path.
def commonpath(paths):
"""Given a sequence of path names, returns the longest common sub-path."""
if not paths:
raise ValueError('commonpath() arg is an empty sequence')
paths = tuple(map(os.fspath, paths))
if isinstance(paths[0], bytes):
sep = b'\\'
altsep = b'/'
curdir = b'.'
else:
sep = '\\'
altsep = '/'
curdir = '.'
try:
drivesplits = [splitdrive(p.replace(altsep, sep).lower()) for p in paths]
split_paths = [p.split(sep) for d, p in drivesplits]
try:
isabs, = set(p[:1] == sep for d, p in drivesplits)
except ValueError:
raise ValueError("Can't mix absolute and relative paths") from None
# Check that all drive letters or UNC paths match. The check is made only
# now otherwise type errors for mixing strings and bytes would not be
# caught.
if len(set(d for d, p in drivesplits)) != 1:
raise ValueError("Paths don't have the same drive")
drive, path = splitdrive(paths[0].replace(altsep, sep))
common = path.split(sep)
common = [c for c in common if c and c != curdir]
split_paths = [[c for c in s if c and c != curdir] for s in split_paths]
s1 = min(split_paths)
s2 = max(split_paths)
for i, c in enumerate(s1):
if c != s2[i]:
common = common[:i]
break
else:
common = common[:len(s1)]
prefix = drive + sep if isabs else drive
return prefix + sep.join(common)
except (TypeError, AttributeError):
genericpath._check_arg_types('commonpath', *paths)
raise
# determine if two files are in fact the same file
try:
# GetFinalPathNameByHandle is available starting with Windows 6.0.
# Windows XP and non-Windows OS'es will mock _getfinalpathname.
if sys.getwindowsversion()[:2] >= (6, 0):
from nt import _getfinalpathname
else:
raise ImportError
except (AttributeError, ImportError):
# On Windows XP and earlier, two files are the same if their absolute
# pathnames are the same.
# Non-Windows operating systems fake this method with an XP
# approximation.
def _getfinalpathname(f):
return normcase(abspath(f))
try:
# The genericpath.isdir implementation uses os.stat and checks the mode
# attribute to tell whether or not the path is a directory.
# This is overkill on Windows - just pass the path to GetFileAttributes
# and check the attribute from there.
from nt import _isdir as isdir
except ImportError:
# Use genericpath.isdir as imported above.
pass
File diff suppressed because it is too large Load Diff
@@ -1,3 +0,0 @@
import os
os.path
-3
View File
@@ -1,3 +0,0 @@
import os
os.pat<caret>
@@ -1 +0,0 @@
-1
View File
@@ -1 +0,0 @@
@@ -1 +0,0 @@
@@ -1,2 +0,0 @@
from os import popen
ret = popen("non-existent-command").close()
@@ -1,6 +0,0 @@
def popen(command, mode='r', bufsize=-1):
pass
class _wrap_close:
def close(self):
pass
@@ -30,14 +30,14 @@ b = B()
open(<warning descr="Unexpected type(s):(B)Possible types:(Union[str, bytes, int])(Union[str, bytes, int, PathLike])">b</warning>)
os.fspath(b) # TODO fail after enabling pyi-stubs for `os` module
os.fsencode(b) # TODO fail after enabling pyi-stubs for `os` module
os.fsdecode(b) # TODO fail after enabling pyi-stubs for `os` module
os.fspath(<warning descr="Unexpected type(s):(B)Possible types:(PathLike)(bytes)(str)">b</warning>)
os.fsencode(<warning descr="Unexpected type(s):(B)Possible types:(Union[str, bytes])(Union[str, bytes, PathLike])">b</warning>)
os.fsdecode(<warning descr="Unexpected type(s):(B)Possible types:(Union[str, bytes])(Union[str, bytes, PathLike])">b</warning>)
Path(<warning descr="Unexpected type(s):(B)Possible types:(Union[str, PurePath])(Union[str, PathLike[str]])">b</warning>)
PurePath(<warning descr="Expected type 'str', got 'B' instead">b</warning>) # TODO update after supporting versioning in pyi-stubs
os.path.abspath(<warning descr="Expected type 'Union[bytes, str, PathLike]', got 'B' instead">b</warning>)
os.path.abspath(<warning descr="Unexpected type(s):(B)Possible types:(AnyStr)(PathLike)">b</warning>)
# pathlib.PurePath
@@ -1,30 +0,0 @@
import abc
import posixpath as path
def _fscodec():
pass
fsencode, fsdecode = _fscodec()
def _fspath(path):
pass
fspath = _fspath
class PathLike(abc.ABC):
"""Abstract base class for implementing the file system path protocol."""
@abc.abstractmethod
def __fspath__(self):
"""Return the file system path representation of the object."""
raise NotImplementedError
@classmethod
def __subclasshook__(cls, subclass):
return hasattr(subclass, '__fspath__')
@@ -1,2 +0,0 @@
def abspath(path):
pass
@@ -1,2 +0,0 @@
from os.path import join
# <ref>
@@ -1,4 +0,0 @@
if a:
import posixpath as path
elif b:
import ntpath as path
@@ -23,7 +23,6 @@ import com.jetbrains.python.sdk.PythonSdkUtil;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@@ -597,28 +596,6 @@ public class PyMultiFileResolveTest extends PyMultiFileResolveTestCase {
assertSameElements(doMultiResolveAndGetFileUrls("pkg1/pkg2/mod1.py"), "pkg1/pkg2/__init__.py");
}
// PY-28764
public void testOsAttributesFromPosixPathAndNTPath() {
myFixture.copyDirectoryToProject(getTestName(true), "");
runWithSourceRoots(
Collections.singletonList(myFixture.findFileInTempDir("lib")),
() -> {
final PsiReference reference = PyResolveTestCase.findReferenceByMarker(myFixture.configureByFile("a.py"));
assertInstanceOf(reference, PsiPolyVariantReference.class);
final List<PsiElement> elements = PyUtil.multiResolveTopPriority((PsiPolyVariantReference)reference);
assertEquals(1, elements.size());
final PsiElement element = elements.get(0);
assertInstanceOf(element, PyFile.class);
final VirtualFile file = ((PyFile)element).getVirtualFile();
assertEquals("ntpath.py", file.getName());
}
);
}
// EA-121262
public void testIncompleteFromImport() {
assertUnresolved();
@@ -28,11 +28,6 @@ public class Py3NoneFunctionAssignmentInspectionTest extends PyInspectionTestCas
return ourPy3Descriptor;
}
// PY-21040
public void testOsPopenClose() {
doMultiFileTest();
}
// PY-28729
public void testGenericSubstitutedWithNone() {
doTestByText(
@@ -149,7 +149,7 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase {
// PY-20769
public void testPathLikePassedToStdlibFunctions() {
doMultiFileTest();
doTest();
}
// PY-21048
@@ -155,7 +155,17 @@ public class PyAddImportQuickFixTest extends PyQuickFixTestCase {
// PY-20976
public void testCombinedElementOrdering() {
doTestProposedImportsOrdering("path", "path from sys", "first.path", "first.second.path()", "os.path", "first._third.path");
runWithAdditionalFileInLibDir(
"os/__init__.py",
"",
(__) ->
runWithAdditionalFileInLibDir(
"os/path.py",
"",
(___) -> doTestProposedImportsOrdering("path",
"path from sys", "first.path", "first.second.path()", "os.path", "first._third.path")
)
);
}
// PY-20976
@@ -163,7 +173,7 @@ public class PyAddImportQuickFixTest extends PyQuickFixTestCase {
runWithAdditionalFileInLibDir(
"sys.py",
"path = 10",
(__) -> doTestProposedImportsOrdering("path", "pkg.path", "sys.path", "os.path")
(__) -> doTestProposedImportsOrdering("path", "pkg.path", "sys.path")
);
}
@@ -172,7 +182,7 @@ public class PyAddImportQuickFixTest extends PyQuickFixTestCase {
runWithAdditionalFileInLibDir(
"sys.py",
"path = 10",
(__) -> doTestProposedImportsOrdering("path", "first.second.path", "sys.path", "os.path", "_private.path")
(__) -> doTestProposedImportsOrdering("path", "first.second.path", "sys.path", "_private.path")
);
}
@@ -193,7 +203,16 @@ public class PyAddImportQuickFixTest extends PyQuickFixTestCase {
// PY-20976
public void testOrderingWithExistingImport() {
doTestProposedImportsOrdering("path", "path from sys", "src.path", "os.path");
runWithAdditionalFileInLibDir(
"os/__init__.py",
"",
(__) ->
runWithAdditionalFileInLibDir(
"os/path.py",
"",
(___) -> doTestProposedImportsOrdering("path", "path from sys", "src.path", "os.path")
)
);
}
private void doTestProposedImportsOrdering(@NotNull String text, @NotNull String... expected) {
@@ -43,15 +43,22 @@ val whiteList = setOf(
"email",
"exceptions",
"functools",
"genericpath",
"io",
"itertools",
"logging",
"macpath",
"math",
"mock",
"multiprocessing",
"ntpath",
"numbers",
"pathlib",
"queue",
"os",
"os2emxpath",
"posix",
"posixpath",
"re",
"shutil",
"signal",