mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
pathlib ABCs: drop partial, broken, untested support for bytes
paths. (#114777)
Methods like `full_match()`, `glob()`, etc, are difficult to make work with byte paths, and it's not worth the effort. This patch makes `PurePathBase` raise `TypeError` when given non-`str` path segments.
This commit is contained in:
parent
1667c28686
commit
574291963f
3 changed files with 29 additions and 21 deletions
|
@ -207,6 +207,9 @@ class PurePathBase:
|
|||
|
||||
def __init__(self, path, *paths):
|
||||
self._raw_path = self.pathmod.join(path, *paths) if paths else path
|
||||
if not isinstance(self._raw_path, str):
|
||||
raise TypeError(
|
||||
f"path should be a str, not {type(self._raw_path).__name__!r}")
|
||||
self._resolving = False
|
||||
|
||||
def with_segments(self, *pathsegments):
|
||||
|
@ -321,8 +324,6 @@ class PurePathBase:
|
|||
other = self.with_segments(other)
|
||||
anchor0, parts0 = self._stack
|
||||
anchor1, parts1 = other._stack
|
||||
if isinstance(anchor0, str) != isinstance(anchor1, str):
|
||||
raise TypeError(f"{self._raw_path!r} and {other._raw_path!r} have different types")
|
||||
if anchor0 != anchor1:
|
||||
raise ValueError(f"{self._raw_path!r} and {other._raw_path!r} have different anchors")
|
||||
while parts0 and parts1 and parts0[-1] == parts1[-1]:
|
||||
|
@ -346,8 +347,6 @@ class PurePathBase:
|
|||
other = self.with_segments(other)
|
||||
anchor0, parts0 = self._stack
|
||||
anchor1, parts1 = other._stack
|
||||
if isinstance(anchor0, str) != isinstance(anchor1, str):
|
||||
raise TypeError(f"{self._raw_path!r} and {other._raw_path!r} have different types")
|
||||
if anchor0 != anchor1:
|
||||
return False
|
||||
while parts0 and parts1 and parts0[-1] == parts1[-1]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue