2 from _typeshed import (
5 OpenBinaryModeUpdating,
11 from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
12 from os import PathLike, stat_result
13 from types import TracebackType
14 from typing import IO, Any, BinaryIO, Generator, Sequence, Tuple, Type, TypeVar, overload
15 from typing_extensions import Literal
17 if sys.version_info >= (3, 9):
18 from types import GenericAlias
20 _P = TypeVar("_P", bound=PurePath)
22 class PurePath(PathLike[str]):
23 parts: Tuple[str, ...]
31 def __new__(cls: Type[_P], *args: StrPath) -> _P: ...
32 def __hash__(self) -> int: ...
33 def __lt__(self, other: PurePath) -> bool: ...
34 def __le__(self, other: PurePath) -> bool: ...
35 def __gt__(self, other: PurePath) -> bool: ...
36 def __ge__(self, other: PurePath) -> bool: ...
37 def __truediv__(self: _P, key: StrPath) -> _P: ...
38 def __rtruediv__(self: _P, key: StrPath) -> _P: ...
39 def __bytes__(self) -> bytes: ...
40 def as_posix(self) -> str: ...
41 def as_uri(self) -> str: ...
42 def is_absolute(self) -> bool: ...
43 def is_reserved(self) -> bool: ...
44 if sys.version_info >= (3, 9):
45 def is_relative_to(self, *other: StrPath) -> bool: ...
46 def match(self, path_pattern: str) -> bool: ...
47 def relative_to(self: _P, *other: StrPath) -> _P: ...
48 def with_name(self: _P, name: str) -> _P: ...
49 if sys.version_info >= (3, 9):
50 def with_stem(self: _P, stem: str) -> _P: ...
51 def with_suffix(self: _P, suffix: str) -> _P: ...
52 def joinpath(self: _P, *other: StrPath) -> _P: ...
54 def parents(self: _P) -> Sequence[_P]: ...
56 def parent(self: _P) -> _P: ...
57 if sys.version_info >= (3, 9):
58 def __class_getitem__(cls, type: Any) -> GenericAlias: ...
60 class PurePosixPath(PurePath): ...
61 class PureWindowsPath(PurePath): ...
64 def __new__(cls: Type[_P], *args: StrPath, **kwargs: Any) -> _P: ...
65 def __enter__(self: Self) -> Self: ...
67 self, exc_type: Type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
70 def cwd(cls: Type[_P]) -> _P: ...
71 if sys.version_info >= (3, 10):
72 def stat(self, *, follow_symlinks: bool = ...) -> stat_result: ...
73 def chmod(self, mode: int, *, follow_symlinks: bool = ...) -> None: ...
75 def stat(self) -> stat_result: ...
76 def chmod(self, mode: int) -> None: ...
77 def exists(self) -> bool: ...
78 def glob(self: _P, pattern: str) -> Generator[_P, None, None]: ...
79 def group(self) -> str: ...
80 def is_dir(self) -> bool: ...
81 def is_file(self) -> bool: ...
82 if sys.version_info >= (3, 7):
83 def is_mount(self) -> bool: ...
84 def is_symlink(self) -> bool: ...
85 def is_socket(self) -> bool: ...
86 def is_fifo(self) -> bool: ...
87 def is_block_device(self) -> bool: ...
88 def is_char_device(self) -> bool: ...
89 def iterdir(self: _P) -> Generator[_P, None, None]: ...
90 def lchmod(self, mode: int) -> None: ...
91 def lstat(self) -> stat_result: ...
92 def mkdir(self, mode: int = ..., parents: bool = ..., exist_ok: bool = ...) -> None: ...
93 # Adapted from builtins.open
94 # Text mode: always returns a TextIOWrapper
95 # The Traversable .open in stdlib/importlib/abc.pyi should be kept in sync with this.
99 mode: OpenTextMode = ...,
100 buffering: int = ...,
101 encoding: str | None = ...,
102 errors: str | None = ...,
103 newline: str | None = ...,
104 ) -> TextIOWrapper: ...
105 # Unbuffered binary mode: returns a FileIO
108 self, mode: OpenBinaryMode, buffering: Literal[0], encoding: None = ..., errors: None = ..., newline: None = ...
110 # Buffering is on: return BufferedRandom, BufferedReader, or BufferedWriter
114 mode: OpenBinaryModeUpdating,
115 buffering: Literal[-1, 1] = ...,
116 encoding: None = ...,
119 ) -> BufferedRandom: ...
123 mode: OpenBinaryModeWriting,
124 buffering: Literal[-1, 1] = ...,
125 encoding: None = ...,
128 ) -> BufferedWriter: ...
132 mode: OpenBinaryModeReading,
133 buffering: Literal[-1, 1] = ...,
134 encoding: None = ...,
137 ) -> BufferedReader: ...
138 # Buffering cannot be determined: fall back to BinaryIO
141 self, mode: OpenBinaryMode, buffering: int, encoding: None = ..., errors: None = ..., newline: None = ...
143 # Fallback if mode is not specified
146 self, mode: str, buffering: int = ..., encoding: str | None = ..., errors: str | None = ..., newline: str | None = ...
148 def owner(self) -> str: ...
149 if sys.version_info >= (3, 9):
150 def readlink(self: _P) -> _P: ...
151 if sys.version_info >= (3, 8):
152 def rename(self: _P, target: str | PurePath) -> _P: ...
153 def replace(self: _P, target: str | PurePath) -> _P: ...
155 def rename(self, target: str | PurePath) -> None: ...
156 def replace(self, target: str | PurePath) -> None: ...
157 def resolve(self: _P, strict: bool = ...) -> _P: ...
158 def rglob(self: _P, pattern: str) -> Generator[_P, None, None]: ...
159 def rmdir(self) -> None: ...
160 def symlink_to(self, target: str | Path, target_is_directory: bool = ...) -> None: ...
161 if sys.version_info >= (3, 10):
162 def hardlink_to(self, target: str | Path) -> None: ...
163 def touch(self, mode: int = ..., exist_ok: bool = ...) -> None: ...
164 if sys.version_info >= (3, 8):
165 def unlink(self, missing_ok: bool = ...) -> None: ...
167 def unlink(self) -> None: ...
169 def home(cls: Type[_P]) -> _P: ...
170 def absolute(self: _P) -> _P: ...
171 def expanduser(self: _P) -> _P: ...
172 def read_bytes(self) -> bytes: ...
173 def read_text(self, encoding: str | None = ..., errors: str | None = ...) -> str: ...
174 def samefile(self, other_path: str | bytes | int | Path) -> bool: ...
175 def write_bytes(self, data: bytes) -> int: ...
176 if sys.version_info >= (3, 10):
178 self, data: str, encoding: str | None = ..., errors: str | None = ..., newline: str | None = ...
181 def write_text(self, data: str, encoding: str | None = ..., errors: str | None = ...) -> int: ...
182 if sys.version_info >= (3, 8):
183 def link_to(self, target: StrPath | bytes) -> None: ...
185 class PosixPath(Path, PurePosixPath): ...
186 class WindowsPath(Path, PureWindowsPath): ...