diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-01-06 21:37:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-06 21:37:38 (GMT) |
commit | a15a7735e69862fdfc0ed21bc1ade3a32833a01d (patch) | |
tree | 8686f98cb96a96591425c0eb3e04bb088cd576a2 /Lib/pathlib | |
parent | 37bd893a22b784d573b71df5417d855dc32dee62 (diff) | |
download | cpython-a15a7735e69862fdfc0ed21bc1ade3a32833a01d.zip cpython-a15a7735e69862fdfc0ed21bc1ade3a32833a01d.tar.gz cpython-a15a7735e69862fdfc0ed21bc1ade3a32833a01d.tar.bz2 |
GH-113528: Deoptimise `pathlib._abc.PurePathBase.relative_to()` (#113529)
Replace use of `_from_parsed_parts()` with `with_segments()` in
`PurePathBase.relative_to()`, and move the assignment of `_drv`, `_root`
and `_tail_cached` slots into `PurePath.relative_to()`.
Diffstat (limited to 'Lib/pathlib')
-rw-r--r-- | Lib/pathlib/__init__.py | 5 | ||||
-rw-r--r-- | Lib/pathlib/_abc.py | 2 |
2 files changed, 5 insertions, 2 deletions
diff --git a/Lib/pathlib/__init__.py b/Lib/pathlib/__init__.py index d83f292..a432d45 100644 --- a/Lib/pathlib/__init__.py +++ b/Lib/pathlib/__init__.py @@ -245,7 +245,10 @@ class PurePath(_abc.PurePathBase): "scheduled for removal in Python 3.14") warnings.warn(msg, DeprecationWarning, stacklevel=2) other = self.with_segments(other, *_deprecated) - return _abc.PurePathBase.relative_to(self, other, walk_up=walk_up) + path = _abc.PurePathBase.relative_to(self, other, walk_up=walk_up) + path._drv = path._root = '' + path._tail_cached = path._raw_paths.copy() + return path def is_relative_to(self, other, /, *_deprecated): """Return True if the path is relative to another path or False. diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py index aca2bd5..97663b9 100644 --- a/Lib/pathlib/_abc.py +++ b/Lib/pathlib/_abc.py @@ -371,7 +371,7 @@ class PurePathBase: else: raise ValueError(f"{str(self)!r} and {str(other)!r} have different anchors") parts = ['..'] * step + self._tail[len(path._tail):] - return self._from_parsed_parts('', '', parts) + return self.with_segments(*parts) def is_relative_to(self, other): """Return True if the path is relative to another path or False. |