summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib.py
diff options
context:
space:
mode:
authorHai Shi <shihai1992@gmail.com>2019-08-13 19:54:02 (GMT)
committerAntoine Pitrou <antoine@python.org>2019-08-13 19:54:02 (GMT)
commit82642a052dc46b2180679518bc8d87e1a28a88b5 (patch)
tree8a987a065e51338c28d01dc359b404dc72717f0d /Lib/pathlib.py
parent8a784af750fa82c8355903309e5089eb2b60c16b (diff)
downloadcpython-82642a052dc46b2180679518bc8d87e1a28a88b5.zip
cpython-82642a052dc46b2180679518bc8d87e1a28a88b5.tar.gz
cpython-82642a052dc46b2180679518bc8d87e1a28a88b5.tar.bz2
bpo-37689: add Path.is_relative_to() method (GH-14982)
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r--Lib/pathlib.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 6355ae8..80923c7 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -886,6 +886,15 @@ class PurePath(object):
return self._from_parsed_parts('', root if n == 1 else '',
abs_parts[n:])
+ def is_relative_to(self, *other):
+ """Return True if the path is relative to another path or False.
+ """
+ try:
+ self.relative_to(*other)
+ return True
+ except ValueError:
+ return False
+
@property
def parts(self):
"""An object providing sequence-like access to the