mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 21:46:42 +08:00
use _typeshed's Path aliases (#4214)
This commit is contained in:
@@ -6,24 +6,22 @@ import sys
|
||||
# cases don't use them.
|
||||
|
||||
from typing import (
|
||||
List, Iterable, Callable, Any, Tuple, Sequence, NamedTuple, IO,
|
||||
List, Iterable, Callable, Any, Tuple, Sequence, NamedTuple,
|
||||
AnyStr, Optional, Union, Set, TypeVar, overload, Type, Protocol, Text
|
||||
)
|
||||
from _typeshed import StrPath
|
||||
|
||||
if sys.version_info >= (3, 6):
|
||||
_Path = Union[str, os.PathLike[str]]
|
||||
_AnyStr = str
|
||||
_AnyPath = TypeVar("_AnyPath", str, os.PathLike[str])
|
||||
# Return value of some functions that may either return a path-like object that was passed in or
|
||||
# a string
|
||||
_PathReturn = Any
|
||||
elif sys.version_info >= (3,):
|
||||
_Path = str
|
||||
_AnyStr = str
|
||||
_AnyPath = str
|
||||
_PathReturn = str
|
||||
else:
|
||||
_Path = Text
|
||||
_AnyStr = TypeVar("_AnyStr", str, unicode)
|
||||
_AnyPath = TypeVar("_AnyPath", str, unicode)
|
||||
_PathReturn = Type[None]
|
||||
@@ -53,40 +51,40 @@ def copyfileobj(fsrc: _Reader[AnyStr], fdst: _Writer[AnyStr],
|
||||
length: int = ...) -> None: ...
|
||||
|
||||
if sys.version_info >= (3,):
|
||||
def copyfile(src: _Path, dst: _AnyPath, *,
|
||||
def copyfile(src: StrPath, dst: _AnyPath, *,
|
||||
follow_symlinks: bool = ...) -> _AnyPath: ...
|
||||
def copymode(src: _Path, dst: _Path, *,
|
||||
def copymode(src: StrPath, dst: StrPath, *,
|
||||
follow_symlinks: bool = ...) -> None: ...
|
||||
def copystat(src: _Path, dst: _Path, *,
|
||||
def copystat(src: StrPath, dst: StrPath, *,
|
||||
follow_symlinks: bool = ...) -> None: ...
|
||||
def copy(src: _Path, dst: _Path, *,
|
||||
def copy(src: StrPath, dst: StrPath, *,
|
||||
follow_symlinks: bool = ...) -> _PathReturn: ...
|
||||
def copy2(src: _Path, dst: _Path, *,
|
||||
def copy2(src: StrPath, dst: StrPath, *,
|
||||
follow_symlinks: bool = ...) -> _PathReturn: ...
|
||||
else:
|
||||
def copyfile(src: _Path, dst: _Path) -> None: ...
|
||||
def copymode(src: _Path, dst: _Path) -> None: ...
|
||||
def copystat(src: _Path, dst: _Path) -> None: ...
|
||||
def copy(src: _Path, dst: _Path) -> _PathReturn: ...
|
||||
def copy2(src: _Path, dst: _Path) -> _PathReturn: ...
|
||||
def copyfile(src: StrPath, dst: StrPath) -> None: ...
|
||||
def copymode(src: StrPath, dst: StrPath) -> None: ...
|
||||
def copystat(src: StrPath, dst: StrPath) -> None: ...
|
||||
def copy(src: StrPath, dst: StrPath) -> _PathReturn: ...
|
||||
def copy2(src: StrPath, dst: StrPath) -> _PathReturn: ...
|
||||
|
||||
def ignore_patterns(*patterns: _Path) -> Callable[[Any, List[_AnyStr]], Set[_AnyStr]]: ...
|
||||
def ignore_patterns(*patterns: StrPath) -> Callable[[Any, List[_AnyStr]], Set[_AnyStr]]: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
def copytree(
|
||||
src: _Path,
|
||||
dst: _Path,
|
||||
src: StrPath,
|
||||
dst: StrPath,
|
||||
symlinks: bool = ...,
|
||||
ignore: Union[None, Callable[[str, List[str]], Iterable[str]], Callable[[_Path, List[str]], Iterable[str]]] = ...,
|
||||
ignore: Union[None, Callable[[str, List[str]], Iterable[str]], Callable[[StrPath, List[str]], Iterable[str]]] = ...,
|
||||
copy_function: Callable[[str, str], None] = ...,
|
||||
ignore_dangling_symlinks: bool = ...,
|
||||
dirs_exist_ok: bool = ...,
|
||||
) -> _PathReturn: ...
|
||||
elif sys.version_info >= (3,):
|
||||
def copytree(src: _Path, dst: _Path, symlinks: bool = ...,
|
||||
def copytree(src: StrPath, dst: StrPath, symlinks: bool = ...,
|
||||
ignore: Union[None,
|
||||
Callable[[str, List[str]], Iterable[str]],
|
||||
Callable[[_Path, List[str]], Iterable[str]]] = ...,
|
||||
Callable[[StrPath, List[str]], Iterable[str]]] = ...,
|
||||
copy_function: Callable[[str, str], None] = ...,
|
||||
ignore_dangling_symlinks: bool = ...) -> _PathReturn: ...
|
||||
else:
|
||||
@@ -96,42 +94,42 @@ else:
|
||||
Iterable[AnyStr]]] = ...) -> _PathReturn: ...
|
||||
|
||||
if sys.version_info >= (3,):
|
||||
def rmtree(path: Union[bytes, _Path], ignore_errors: bool = ...,
|
||||
def rmtree(path: Union[bytes, StrPath], ignore_errors: bool = ...,
|
||||
onerror: Optional[Callable[[Any, Any, Any], Any]] = ...) -> None: ...
|
||||
else:
|
||||
def rmtree(path: _AnyPath, ignore_errors: bool = ...,
|
||||
onerror: Optional[Callable[[Any, _AnyPath, Any], Any]] = ...) -> None: ...
|
||||
|
||||
_CopyFn = Union[Callable[[str, str], None], Callable[[_Path, _Path], None]]
|
||||
_CopyFn = Union[Callable[[str, str], None], Callable[[StrPath, StrPath], None]]
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
def move(src: _Path, dst: _Path,
|
||||
def move(src: StrPath, dst: StrPath,
|
||||
copy_function: _CopyFn = ...) -> _PathReturn: ...
|
||||
elif sys.version_info >= (3, 5):
|
||||
# See https://bugs.python.org/issue32689
|
||||
def move(src: str, dst: _Path,
|
||||
def move(src: str, dst: StrPath,
|
||||
copy_function: _CopyFn = ...) -> _PathReturn: ...
|
||||
else:
|
||||
def move(src: _Path, dst: _Path) -> _PathReturn: ...
|
||||
def move(src: StrPath, dst: StrPath) -> _PathReturn: ...
|
||||
|
||||
if sys.version_info >= (3,):
|
||||
class _ntuple_diskusage(NamedTuple):
|
||||
total: int
|
||||
used: int
|
||||
free: int
|
||||
def disk_usage(path: _Path) -> _ntuple_diskusage: ...
|
||||
def chown(path: _Path, user: Optional[str] = ...,
|
||||
def disk_usage(path: StrPath) -> _ntuple_diskusage: ...
|
||||
def chown(path: StrPath, user: Optional[str] = ...,
|
||||
group: Optional[str] = ...) -> None: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
@overload
|
||||
def which(cmd: _Path, mode: int = ..., path: Optional[_Path] = ...) -> Optional[str]: ...
|
||||
def which(cmd: StrPath, mode: int = ..., path: Optional[StrPath] = ...) -> Optional[str]: ...
|
||||
@overload
|
||||
def which(cmd: bytes, mode: int = ..., path: Optional[_Path] = ...) -> Optional[bytes]: ...
|
||||
def which(cmd: bytes, mode: int = ..., path: Optional[StrPath] = ...) -> Optional[bytes]: ...
|
||||
elif sys.version_info >= (3,):
|
||||
def which(cmd: _Path, mode: int = ..., path: Optional[_Path] = ...) -> Optional[str]: ...
|
||||
def which(cmd: StrPath, mode: int = ..., path: Optional[StrPath] = ...) -> Optional[str]: ...
|
||||
|
||||
def make_archive(base_name: _AnyStr, format: str, root_dir: Optional[_Path] = ...,
|
||||
base_dir: Optional[_Path] = ..., verbose: bool = ...,
|
||||
def make_archive(base_name: _AnyStr, format: str, root_dir: Optional[StrPath] = ...,
|
||||
base_dir: Optional[StrPath] = ..., verbose: bool = ...,
|
||||
dry_run: bool = ..., owner: Optional[str] = ..., group: Optional[str] = ...,
|
||||
logger: Optional[Any] = ...) -> _AnyStr: ...
|
||||
def get_archive_formats() -> List[Tuple[str, str]]: ...
|
||||
@@ -143,11 +141,11 @@ def unregister_archive_format(name: str) -> None: ...
|
||||
|
||||
if sys.version_info >= (3,):
|
||||
if sys.version_info >= (3, 7):
|
||||
def unpack_archive(filename: _Path, extract_dir: Optional[_Path] = ...,
|
||||
def unpack_archive(filename: StrPath, extract_dir: Optional[StrPath] = ...,
|
||||
format: Optional[str] = ...) -> None: ...
|
||||
else:
|
||||
# See http://bugs.python.org/issue30218
|
||||
def unpack_archive(filename: str, extract_dir: Optional[_Path] = ...,
|
||||
def unpack_archive(filename: str, extract_dir: Optional[StrPath] = ...,
|
||||
format: Optional[str] = ...) -> None: ...
|
||||
def register_unpack_format(name: str, extensions: List[str], function: Any,
|
||||
extra_args: Sequence[Tuple[str, Any]] = ...,
|
||||
|
||||
Reference in New Issue
Block a user