mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 21:14:48 +08:00
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:
@@ -1,97 +1,70 @@
|
||||
import os
|
||||
import sys
|
||||
from _typeshed import AnyPath, BytesPath, StrPath
|
||||
from genericpath import exists as exists
|
||||
from _typeshed import BytesPath, StrPath
|
||||
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
|
||||
|
||||
_T = TypeVar("_T")
|
||||
# Re-export common definitions from posixpath to reduce duplication
|
||||
from posixpath import (
|
||||
abspath as abspath,
|
||||
basename as basename,
|
||||
commonpath as commonpath,
|
||||
curdir as curdir,
|
||||
defpath as defpath,
|
||||
devnull as devnull,
|
||||
dirname as dirname,
|
||||
expanduser as expanduser,
|
||||
expandvars as expandvars,
|
||||
extsep as extsep,
|
||||
isabs as isabs,
|
||||
islink as islink,
|
||||
ismount as ismount,
|
||||
lexists as lexists,
|
||||
normcase as normcase,
|
||||
normpath as normpath,
|
||||
pardir as pardir,
|
||||
pathsep as pathsep,
|
||||
relpath as relpath,
|
||||
sep as sep,
|
||||
split as split,
|
||||
splitdrive as splitdrive,
|
||||
splitext as splitext,
|
||||
supports_unicode_filenames as supports_unicode_filenames,
|
||||
)
|
||||
from typing import AnyStr, Tuple, overload
|
||||
|
||||
# ----- 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
|
||||
altsep: str
|
||||
if sys.version_info < (3, 7) and sys.platform == "win32":
|
||||
def splitunc(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated
|
||||
|
||||
# ----- os.path function stubs -----
|
||||
# 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(p: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def basename(p: AnyStr) -> AnyStr: ...
|
||||
@overload
|
||||
def dirname(p: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def dirname(p: 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(s: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def normcase(s: AnyStr) -> AnyStr: ...
|
||||
@overload
|
||||
def normpath(path: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def normpath(path: AnyStr) -> AnyStr: ...
|
||||
@overload
|
||||
def realpath(path: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def realpath(path: 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: ...
|
||||
# Similar to posixpath, but have slightly different argument names
|
||||
@overload
|
||||
def join(path: StrPath, *paths: StrPath) -> str: ...
|
||||
@overload
|
||||
def join(path: 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
|
||||
def split(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
|
||||
@overload
|
||||
def splitdrive(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
|
||||
@overload
|
||||
def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
|
||||
@overload
|
||||
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
|
||||
if sys.platform == "win32":
|
||||
if sys.version_info >= (3, 10):
|
||||
@overload
|
||||
def realpath(path: PathLike[AnyStr], *, strict: bool = ...) -> AnyStr: ...
|
||||
@overload
|
||||
def realpath(path: AnyStr, *, strict: bool = ...) -> AnyStr: ...
|
||||
else:
|
||||
@overload
|
||||
def realpath(path: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def realpath(path: AnyStr) -> AnyStr: ...
|
||||
|
||||
else:
|
||||
realpath = abspath
|
||||
|
||||
Reference in New Issue
Block a user