summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib/_local.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-11-05 21:19:36 (GMT)
committerGitHub <noreply@github.com>2024-11-05 21:19:36 (GMT)
commit5e9168492f12c579b2481f3f3e0ae11f9d986857 (patch)
tree08e03f719d3f6eb690b70e7d8b246731d6dae31a /Lib/pathlib/_local.py
parentf51fd84034e2cbf458321c25ba6fd085a39d6f6f (diff)
downloadcpython-5e9168492f12c579b2481f3f3e0ae11f9d986857.zip
cpython-5e9168492f12c579b2481f3f3e0ae11f9d986857.tar.gz
cpython-5e9168492f12c579b2481f3f3e0ae11f9d986857.tar.bz2
pathlib ABCs: defer path joining (#126409)
Defer joining of path segments in the private `PurePathBase` ABC. The new behaviour matches how the public `PurePath` class handles path segments. This removes a hard-to-grok difference between the ABCs and the main classes. It also slightly reduces the size of `PurePath` objects by eliminating a `_raw_path` slot.
Diffstat (limited to 'Lib/pathlib/_local.py')
-rw-r--r--Lib/pathlib/_local.py25
1 files changed, 6 insertions, 19 deletions
diff --git a/Lib/pathlib/_local.py b/Lib/pathlib/_local.py
index 99474e1..b27f456 100644
--- a/Lib/pathlib/_local.py
+++ b/Lib/pathlib/_local.py
@@ -68,10 +68,6 @@ class PurePath(PurePathBase):
"""
__slots__ = (
- # The `_raw_paths` slot stores unnormalized string paths. This is set
- # in the `__init__()` method.
- '_raw_paths',
-
# The `_drv`, `_root` and `_tail_cached` slots store parsed and
# normalized parts of the path. They are set when any of the `drive`,
# `root` or `_tail` properties are accessed for the first time. The
@@ -300,24 +296,13 @@ class PurePath(PurePathBase):
return parts
@property
- def _raw_path(self):
- """The joined but unnormalized path."""
- paths = self._raw_paths
- if len(paths) == 0:
- path = ''
- elif len(paths) == 1:
- path = paths[0]
- else:
- path = self.parser.join(*paths)
- return path
-
- @property
def drive(self):
"""The drive prefix (letter or UNC path), if any."""
try:
return self._drv
except AttributeError:
- self._drv, self._root, self._tail_cached = self._parse_path(self._raw_path)
+ raw_path = PurePathBase.__str__(self)
+ self._drv, self._root, self._tail_cached = self._parse_path(raw_path)
return self._drv
@property
@@ -326,7 +311,8 @@ class PurePath(PurePathBase):
try:
return self._root
except AttributeError:
- self._drv, self._root, self._tail_cached = self._parse_path(self._raw_path)
+ raw_path = PurePathBase.__str__(self)
+ self._drv, self._root, self._tail_cached = self._parse_path(raw_path)
return self._root
@property
@@ -334,7 +320,8 @@ class PurePath(PurePathBase):
try:
return self._tail_cached
except AttributeError:
- self._drv, self._root, self._tail_cached = self._parse_path(self._raw_path)
+ raw_path = PurePathBase.__str__(self)
+ self._drv, self._root, self._tail_cached = self._parse_path(raw_path)
return self._tail_cached
@property