summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-01-31 00:59:33 (GMT)
committerGitHub <noreply@github.com>2024-01-31 00:59:33 (GMT)
commit574291963f6b0eb7da3fde1ae9763236e7ece306 (patch)
tree54639605dc0db7b2e69c0b54527ca939a9acaa4d /Lib/pathlib
parent1667c2868633a1091b3519594103ca7662d64d75 (diff)
downloadcpython-574291963f6b0eb7da3fde1ae9763236e7ece306.zip
cpython-574291963f6b0eb7da3fde1ae9763236e7ece306.tar.gz
cpython-574291963f6b0eb7da3fde1ae9763236e7ece306.tar.bz2
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.
Diffstat (limited to 'Lib/pathlib')
-rw-r--r--Lib/pathlib/_abc.py7
1 files changed, 3 insertions, 4 deletions
diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py
index 85884bc..91f5cd6 100644
--- a/Lib/pathlib/_abc.py
+++ b/Lib/pathlib/_abc.py
@@ -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]: