|
15 | 15 | from pathlib._os import magic_open, ensure_distinct_paths, ensure_different_files, copyfileobj |
16 | 16 | from pathlib import PurePath, Path |
17 | 17 | from typing import ( |
18 | | - Any, BinaryIO, Callable, Generator, Iterator, Optional, Protocol, Sequence, TypeVar, Union, |
| 18 | + Any, BinaryIO, Callable, Generator, Iterator, Literal, Optional, Protocol, Sequence, TypeVar, |
19 | 19 | runtime_checkable, |
20 | 20 | ) |
21 | 21 |
|
22 | | - |
23 | 22 | _JP = TypeVar("_JP", bound="_JoinablePath") |
24 | 23 | _RP = TypeVar("_RP", bound="_ReadablePath") |
25 | 24 | _WP = TypeVar("_WP", bound="_WritablePath") |
26 | 25 |
|
27 | 26 |
|
28 | | -def _explode_path(path, split): |
| 27 | +def _explode_path(path: str, split: Callable[[str], tuple[str, str]]) -> tuple[str, list[str]]: |
29 | 28 | """ |
30 | 29 | Split the path into a 2-tuple (anchor, parts), where *anchor* is the |
31 | 30 | uppermost parent of the path (equivalent to path.parents[-1]), and |
@@ -85,7 +84,7 @@ def parser(self) -> _PathParser: |
85 | 84 | raise NotImplementedError |
86 | 85 |
|
87 | 86 | @abstractmethod |
88 | | - def with_segments(self: _JP, *pathsegments: Union[_JP, str]) -> _JP: |
| 87 | + def with_segments(self: _JP, *pathsegments: str) -> _JP: |
89 | 88 | """Construct a new path object from any number of path-like objects. |
90 | 89 | Subclasses may override this method to customize how new path objects |
91 | 90 | are created from methods like `iterdir()`. |
@@ -180,21 +179,21 @@ def parts(self) -> Sequence[str]: |
180 | 179 | parts.append(anchor) |
181 | 180 | return tuple(reversed(parts)) |
182 | 181 |
|
183 | | - def joinpath(self: _JP, *pathsegments: Union[_JP, str]) -> _JP: |
| 182 | + def joinpath(self: _JP, *pathsegments: str) -> _JP: |
184 | 183 | """Combine this path with one or several arguments, and return a |
185 | 184 | new path representing either a subpath (if all arguments are relative |
186 | 185 | paths) or a totally different path (if one of the arguments is |
187 | 186 | anchored). |
188 | 187 | """ |
189 | 188 | return self.with_segments(str(self), *pathsegments) |
190 | 189 |
|
191 | | - def __truediv__(self: _JP, key: Union[_JP, str]) -> _JP: |
| 190 | + def __truediv__(self: _JP, key: str) -> _JP: |
192 | 191 | try: |
193 | 192 | return self.with_segments(str(self), key) |
194 | 193 | except TypeError: |
195 | 194 | return NotImplemented |
196 | 195 |
|
197 | | - def __rtruediv__(self: _JP, key: Union[_JP, str]) -> _JP: |
| 196 | + def __rtruediv__(self: _JP, key: str) -> _JP: |
198 | 197 | try: |
199 | 198 | return self.with_segments(key, str(self)) |
200 | 199 | except TypeError: |
@@ -222,7 +221,7 @@ def parents(self: _JP) -> Sequence[_JP]: |
222 | 221 | parent = split(path)[0] |
223 | 222 | return tuple(parents) |
224 | 223 |
|
225 | | - def full_match(self: _JP, pattern: Union[_JP, str]) -> bool: |
| 224 | + def full_match(self: _JP, pattern: str) -> bool: |
226 | 225 | """ |
227 | 226 | Return True if this path matches the given glob-style pattern. The |
228 | 227 | pattern is matched against the entire path. |
@@ -287,7 +286,7 @@ def iterdir(self: _RP) -> Iterator[_RP]: |
287 | 286 | """ |
288 | 287 | raise NotImplementedError |
289 | 288 |
|
290 | | - def glob(self: _RP, pattern: Union[_RP, str], *, recurse_symlinks: bool = True) -> Iterator[_RP]: |
| 289 | + def glob(self: _RP, pattern: str, *, recurse_symlinks: Literal[True] = True) -> Iterator[_RP]: |
291 | 290 | """Iterate over this subtree and yield all existing files (of any |
292 | 291 | kind, including directories) matching the given relative pattern. |
293 | 292 | """ |
@@ -374,7 +373,7 @@ class _WritablePath(_JoinablePath): |
374 | 373 | __slots__ = () |
375 | 374 |
|
376 | 375 | @abstractmethod |
377 | | - def symlink_to(self: _WP, target: _WP, target_is_directory: bool = False) -> None: |
| 376 | + def symlink_to(self, target: str, target_is_directory: bool = False) -> None: |
378 | 377 | """ |
379 | 378 | Make this path a symlink pointing to the target path. |
380 | 379 | Note the order of arguments (link, target) is the reverse of os.symlink. |
|
0 commit comments