various path stubs: re-export to reduce duplication (#5382)

Co-authored-by: hauntsaninja <>
Co-authored-by: Akuli <akuviljanen17@gmail.com>
This commit is contained in:
Shantanu
2021-05-10 22:27:13 -07:00
committed by GitHub
parent 0ac3531a93
commit a91c89ea94
7 changed files with 164 additions and 349 deletions

View File

@@ -1,29 +1,32 @@
import os
import sys
from _typeshed import AnyPath, BytesPath, StrPath
from genericpath import exists as exists
from genericpath import (
commonprefix as commonprefix,
exists as exists,
getatime as getatime,
getctime as getctime,
getmtime as getmtime,
getsize as getsize,
isdir as isdir,
isfile as isfile,
samefile as samefile,
sameopenfile as sameopenfile,
samestat as samestat,
)
from os import PathLike
from os.path import commonpath as commonpath, commonprefix as commonprefix, lexists as lexists
from typing import AnyStr, Optional, Tuple, TypeVar, overload
from typing import AnyStr, Optional, Sequence, Tuple, overload
_T = TypeVar("_T")
# ----- 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]
altsep: Optional[str]
extsep: str
pathsep: str
defpath: str
devnull: str
# ----- os.path function stubs -----
# Overloads are necessary to work around python/mypy#3644.
@overload
def abspath(path: PathLike[AnyStr]) -> AnyStr: ...
@@ -53,6 +56,14 @@ def normcase(s: AnyStr) -> AnyStr: ...
def normpath(path: PathLike[AnyStr]) -> AnyStr: ...
@overload
def normpath(path: AnyStr) -> AnyStr: ...
@overload
def commonpath(paths: Sequence[StrPath]) -> str: ...
@overload
def commonpath(paths: Sequence[BytesPath]) -> bytes: ...
@overload
def join(a: StrPath, *paths: StrPath) -> str: ...
@overload
def join(a: BytesPath, *paths: BytesPath) -> bytes: ...
if sys.version_info >= (3, 10):
@overload
@@ -66,28 +77,10 @@ else:
@overload
def realpath(filename: AnyStr) -> AnyStr: ...
# These return float if os.stat_float_times() == True,
# but int is a subclass of float.
def getatime(filename: AnyPath) -> float: ...
def getmtime(filename: AnyPath) -> float: ...
def getctime(filename: AnyPath) -> float: ...
def getsize(filename: AnyPath) -> int: ...
def isabs(s: AnyPath) -> bool: ...
def isfile(path: AnyPath) -> bool: ...
def isdir(s: AnyPath) -> bool: ...
def islink(path: AnyPath) -> bool: ...
def ismount(path: AnyPath) -> bool: ...
@overload
def join(a: StrPath, *paths: StrPath) -> str: ...
@overload
def join(a: BytesPath, *paths: BytesPath) -> bytes: ...
@overload
def relpath(path: BytesPath, start: Optional[BytesPath] = ...) -> bytes: ...
@overload
def relpath(path: StrPath, start: Optional[StrPath] = ...) -> str: ...
def samefile(f1: AnyPath, f2: AnyPath) -> bool: ...
def sameopenfile(fp1: int, fp2: int) -> bool: ...
def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ...
@overload
def split(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
@@ -100,6 +93,7 @@ def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def splitext(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
if sys.version_info < (3, 7) and sys.platform == "win32":
def splitunc(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated
def isabs(s: AnyPath) -> bool: ...
def islink(path: AnyPath) -> bool: ...
def ismount(path: AnyPath) -> bool: ...
def lexists(path: AnyPath) -> bool: ...