Skip to content

Commit d1583c0

Browse files
committed
Update types
- pathsegments are `str`: joinpath, __truediv__, __rtruediv__, with_segments - symlink_to target is `str` - glob recurse_symlinks is `Literal[True]` - full_match and glob pattern is `str`
1 parent 399a213 commit d1583c0

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

Lib/pathlib/types.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@
1515
from pathlib._os import magic_open, ensure_distinct_paths, ensure_different_files, copyfileobj
1616
from pathlib import PurePath, Path
1717
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,
1919
runtime_checkable,
2020
)
2121

22-
2322
_JP = TypeVar("_JP", bound="_JoinablePath")
2423
_RP = TypeVar("_RP", bound="_ReadablePath")
2524
_WP = TypeVar("_WP", bound="_WritablePath")
2625

2726

28-
def _explode_path(path, split):
27+
def _explode_path(path: str, split: Callable[[str], tuple[str, str]]) -> tuple[str, list[str]]:
2928
"""
3029
Split the path into a 2-tuple (anchor, parts), where *anchor* is the
3130
uppermost parent of the path (equivalent to path.parents[-1]), and
@@ -85,7 +84,7 @@ def parser(self) -> _PathParser:
8584
raise NotImplementedError
8685

8786
@abstractmethod
88-
def with_segments(self: _JP, *pathsegments: Union[_JP, str]) -> _JP:
87+
def with_segments(self: _JP, *pathsegments: str) -> _JP:
8988
"""Construct a new path object from any number of path-like objects.
9089
Subclasses may override this method to customize how new path objects
9190
are created from methods like `iterdir()`.
@@ -180,21 +179,21 @@ def parts(self) -> Sequence[str]:
180179
parts.append(anchor)
181180
return tuple(reversed(parts))
182181

183-
def joinpath(self: _JP, *pathsegments: Union[_JP, str]) -> _JP:
182+
def joinpath(self: _JP, *pathsegments: str) -> _JP:
184183
"""Combine this path with one or several arguments, and return a
185184
new path representing either a subpath (if all arguments are relative
186185
paths) or a totally different path (if one of the arguments is
187186
anchored).
188187
"""
189188
return self.with_segments(str(self), *pathsegments)
190189

191-
def __truediv__(self: _JP, key: Union[_JP, str]) -> _JP:
190+
def __truediv__(self: _JP, key: str) -> _JP:
192191
try:
193192
return self.with_segments(str(self), key)
194193
except TypeError:
195194
return NotImplemented
196195

197-
def __rtruediv__(self: _JP, key: Union[_JP, str]) -> _JP:
196+
def __rtruediv__(self: _JP, key: str) -> _JP:
198197
try:
199198
return self.with_segments(key, str(self))
200199
except TypeError:
@@ -222,7 +221,7 @@ def parents(self: _JP) -> Sequence[_JP]:
222221
parent = split(path)[0]
223222
return tuple(parents)
224223

225-
def full_match(self: _JP, pattern: Union[_JP, str]) -> bool:
224+
def full_match(self: _JP, pattern: str) -> bool:
226225
"""
227226
Return True if this path matches the given glob-style pattern. The
228227
pattern is matched against the entire path.
@@ -287,7 +286,7 @@ def iterdir(self: _RP) -> Iterator[_RP]:
287286
"""
288287
raise NotImplementedError
289288

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]:
291290
"""Iterate over this subtree and yield all existing files (of any
292291
kind, including directories) matching the given relative pattern.
293292
"""
@@ -374,7 +373,7 @@ class _WritablePath(_JoinablePath):
374373
__slots__ = ()
375374

376375
@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:
378377
"""
379378
Make this path a symlink pointing to the target path.
380379
Note the order of arguments (link, target) is the reverse of os.symlink.

0 commit comments

Comments
 (0)