PathLike cleanup (#5242)

Copy builtins._PathLike to os.PathLike

Use os.PathLike exclusively outside of builtins
This commit is contained in:
Sebastian Rittau
2021-04-23 19:15:07 +02:00
committed by GitHub
parent 27facc7ff9
commit bac1918b5f
14 changed files with 83 additions and 117 deletions

View File

@@ -1,7 +1,7 @@
import os
import sys
from _typeshed import OpenBinaryMode, OpenBinaryModeReading, OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenTextMode
from _typeshed import OpenBinaryMode, OpenBinaryModeReading, OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenTextMode, StrPath
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
from os import PathLike, stat_result
from types import TracebackType
from typing import IO, Any, BinaryIO, Generator, List, Optional, Sequence, Tuple, Type, TypeVar, Union, overload
from typing_extensions import Literal
@@ -11,10 +11,7 @@ if sys.version_info >= (3, 9):
_P = TypeVar("_P", bound=PurePath)
_PurePathBase = os.PathLike[str]
_PathLike = os.PathLike[str]
class PurePath(_PurePathBase):
class PurePath(PathLike[str]):
parts: Tuple[str, ...]
drive: str
root: str
@@ -23,28 +20,28 @@ class PurePath(_PurePathBase):
suffix: str
suffixes: List[str]
stem: str
def __new__(cls: Type[_P], *args: Union[str, _PathLike]) -> _P: ...
def __new__(cls: Type[_P], *args: StrPath) -> _P: ...
def __hash__(self) -> int: ...
def __lt__(self, other: PurePath) -> bool: ...
def __le__(self, other: PurePath) -> bool: ...
def __gt__(self, other: PurePath) -> bool: ...
def __ge__(self, other: PurePath) -> bool: ...
def __truediv__(self: _P, key: Union[str, _PathLike]) -> _P: ...
def __rtruediv__(self: _P, key: Union[str, _PathLike]) -> _P: ...
def __truediv__(self: _P, key: StrPath) -> _P: ...
def __rtruediv__(self: _P, key: StrPath) -> _P: ...
def __bytes__(self) -> bytes: ...
def as_posix(self) -> str: ...
def as_uri(self) -> str: ...
def is_absolute(self) -> bool: ...
def is_reserved(self) -> bool: ...
if sys.version_info >= (3, 9):
def is_relative_to(self, *other: Union[str, os.PathLike[str]]) -> bool: ...
def is_relative_to(self, *other: StrPath) -> bool: ...
def match(self, path_pattern: str) -> bool: ...
def relative_to(self: _P, *other: Union[str, _PathLike]) -> _P: ...
def relative_to(self: _P, *other: StrPath) -> _P: ...
def with_name(self: _P, name: str) -> _P: ...
if sys.version_info >= (3, 9):
def with_stem(self: _P, stem: str) -> _P: ...
def with_suffix(self: _P, suffix: str) -> _P: ...
def joinpath(self: _P, *other: Union[str, _PathLike]) -> _P: ...
def joinpath(self: _P, *other: StrPath) -> _P: ...
@property
def parents(self: _P) -> Sequence[_P]: ...
@property
@@ -56,14 +53,14 @@ class PurePosixPath(PurePath): ...
class PureWindowsPath(PurePath): ...
class Path(PurePath):
def __new__(cls: Type[_P], *args: Union[str, _PathLike], **kwargs: Any) -> _P: ...
def __new__(cls: Type[_P], *args: StrPath, **kwargs: Any) -> _P: ...
def __enter__(self: _P) -> _P: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_value: Optional[BaseException], traceback: Optional[TracebackType]
) -> Optional[bool]: ...
@classmethod
def cwd(cls: Type[_P]) -> _P: ...
def stat(self) -> os.stat_result: ...
def stat(self) -> stat_result: ...
def chmod(self, mode: int) -> None: ...
def exists(self) -> bool: ...
def glob(self: _P, pattern: str) -> Generator[_P, None, None]: ...
@@ -79,7 +76,7 @@ class Path(PurePath):
def is_char_device(self) -> bool: ...
def iterdir(self: _P) -> Generator[_P, None, None]: ...
def lchmod(self, mode: int) -> None: ...
def lstat(self) -> os.stat_result: ...
def lstat(self) -> stat_result: ...
def mkdir(self, mode: int = ..., parents: bool = ..., exist_ok: bool = ...) -> None: ...
# Adapted from builtins.open
# Text mode: always returns a TextIOWrapper
@@ -168,7 +165,7 @@ class Path(PurePath):
def write_bytes(self, data: bytes) -> int: ...
def write_text(self, data: str, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> int: ...
if sys.version_info >= (3, 8):
def link_to(self, target: Union[str, bytes, os.PathLike[str]]) -> None: ...
def link_to(self, target: Union[StrPath, bytes]) -> None: ...
class PosixPath(Path, PurePosixPath): ...
class WindowsPath(Path, PureWindowsPath): ...