diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-01-05 22:56:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-05 22:56:04 (GMT) |
commit | 3375dfed400494ba5cc1b744d52f6fb8b7796059 (patch) | |
tree | 124c0f4c37fc40590b75e5fb5c8ef43da393298b /Lib/pathlib | |
parent | d99d8712253c3affc54cf7f6e71f161dea8347ce (diff) | |
download | cpython-3375dfed400494ba5cc1b744d52f6fb8b7796059.zip cpython-3375dfed400494ba5cc1b744d52f6fb8b7796059.tar.gz cpython-3375dfed400494ba5cc1b744d52f6fb8b7796059.tar.bz2 |
GH-113568: Stop raising deprecation warnings from pathlib ABCs (#113757)
Diffstat (limited to 'Lib/pathlib')
-rw-r--r-- | Lib/pathlib/__init__.py | 27 | ||||
-rw-r--r-- | Lib/pathlib/_abc.py | 21 |
2 files changed, 31 insertions, 17 deletions
diff --git a/Lib/pathlib/__init__.py b/Lib/pathlib/__init__.py index 6a94886..115ccf7 100644 --- a/Lib/pathlib/__init__.py +++ b/Lib/pathlib/__init__.py @@ -166,6 +166,33 @@ class PurePath(_abc.PurePathBase): return NotImplemented return self._parts_normcase >= other._parts_normcase + def relative_to(self, other, /, *_deprecated, walk_up=False): + """Return the relative path to another path identified by the passed + arguments. If the operation is not possible (because this is not + related to the other path), raise ValueError. + + The *walk_up* parameter controls whether `..` may be used to resolve + the path. + """ + if _deprecated: + msg = ("support for supplying more than one positional argument " + "to pathlib.PurePath.relative_to() is deprecated and " + "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) + + def is_relative_to(self, other, /, *_deprecated): + """Return True if the path is relative to another path or False. + """ + if _deprecated: + msg = ("support for supplying more than one argument to " + "pathlib.PurePath.is_relative_to() is deprecated and " + "scheduled for removal in Python 3.14") + warnings.warn(msg, DeprecationWarning, stacklevel=2) + other = self.with_segments(other, *_deprecated) + return _abc.PurePathBase.is_relative_to(self, other) + def as_uri(self): """Return the path as a URI.""" if not self.is_absolute(): diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py index da8d67f..b1204e8 100644 --- a/Lib/pathlib/_abc.py +++ b/Lib/pathlib/_abc.py @@ -2,7 +2,6 @@ import functools import ntpath import posixpath import sys -import warnings from _collections_abc import Sequence from errno import ENOENT, ENOTDIR, EBADF, ELOOP, EINVAL from itertools import chain @@ -383,7 +382,7 @@ class PurePathBase: else: raise ValueError(f"Invalid suffix {suffix!r}") - def relative_to(self, other, /, *_deprecated, walk_up=False): + def relative_to(self, other, *, walk_up=False): """Return the relative path to another path identified by the passed arguments. If the operation is not possible (because this is not related to the other path), raise ValueError. @@ -391,13 +390,7 @@ class PurePathBase: The *walk_up* parameter controls whether `..` may be used to resolve the path. """ - if _deprecated: - msg = ("support for supplying more than one positional argument " - "to pathlib.PurePath.relative_to() is deprecated and " - "scheduled for removal in Python 3.14") - warnings.warn(msg, DeprecationWarning, stacklevel=2) - other = self.with_segments(other, *_deprecated) - elif not isinstance(other, PurePathBase): + if not isinstance(other, PurePathBase): other = self.with_segments(other) for step, path in enumerate(chain([other], other.parents)): if path == self or path in self.parents: @@ -411,16 +404,10 @@ class PurePathBase: parts = ['..'] * step + self._tail[len(path._tail):] return self._from_parsed_parts('', '', parts) - def is_relative_to(self, other, /, *_deprecated): + def is_relative_to(self, other): """Return True if the path is relative to another path or False. """ - if _deprecated: - msg = ("support for supplying more than one argument to " - "pathlib.PurePath.is_relative_to() is deprecated and " - "scheduled for removal in Python 3.14") - warnings.warn(msg, DeprecationWarning, stacklevel=2) - other = self.with_segments(other, *_deprecated) - elif not isinstance(other, PurePathBase): + if not isinstance(other, PurePathBase): other = self.with_segments(other) return other == self or other in self.parents |