mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +00:00
pathlib ABCs: add _raw_path
property (#113976)
It's wrong for the `PurePathBase` methods to rely so much on `__str__()`. Instead, they should treat the raw path(s) as opaque objects and leave the details to `pathmod`. This commit adds a `PurePathBase._raw_path` property and uses it through many of the other ABC methods. These methods are all redefined in `PurePath` and `Path`, so this has no effect on the public classes.
This commit is contained in:
parent
e4ff131e01
commit
f20b151a1c
2 changed files with 31 additions and 20 deletions
|
@ -257,7 +257,9 @@ class PurePath(_abc.PurePathBase):
|
|||
parsed = [sys.intern(str(x)) for x in rel.split(sep) if x and x != '.']
|
||||
return drv, root, parsed
|
||||
|
||||
def _load_parts(self):
|
||||
@property
|
||||
def _raw_path(self):
|
||||
"""The joined but unnormalized path."""
|
||||
paths = self._raw_paths
|
||||
if len(paths) == 0:
|
||||
path = ''
|
||||
|
@ -265,7 +267,7 @@ class PurePath(_abc.PurePathBase):
|
|||
path = paths[0]
|
||||
else:
|
||||
path = self.pathmod.join(*paths)
|
||||
self._drv, self._root, self._tail_cached = self._parse_path(path)
|
||||
return path
|
||||
|
||||
@property
|
||||
def drive(self):
|
||||
|
@ -273,7 +275,7 @@ class PurePath(_abc.PurePathBase):
|
|||
try:
|
||||
return self._drv
|
||||
except AttributeError:
|
||||
self._load_parts()
|
||||
self._drv, self._root, self._tail_cached = self._parse_path(self._raw_path)
|
||||
return self._drv
|
||||
|
||||
@property
|
||||
|
@ -282,7 +284,7 @@ class PurePath(_abc.PurePathBase):
|
|||
try:
|
||||
return self._root
|
||||
except AttributeError:
|
||||
self._load_parts()
|
||||
self._drv, self._root, self._tail_cached = self._parse_path(self._raw_path)
|
||||
return self._root
|
||||
|
||||
@property
|
||||
|
@ -290,7 +292,7 @@ class PurePath(_abc.PurePathBase):
|
|||
try:
|
||||
return self._tail_cached
|
||||
except AttributeError:
|
||||
self._load_parts()
|
||||
self._drv, self._root, self._tail_cached = self._parse_path(self._raw_path)
|
||||
return self._tail_cached
|
||||
|
||||
@property
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue