bpo-37689: add Path.is_relative_to() method (GH-14982)

This commit is contained in:
Hai Shi 2019-08-13 14:54:02 -05:00 committed by Antoine Pitrou
parent 8a784af750
commit 82642a052d
4 changed files with 111 additions and 1 deletions

View file

@ -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