MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / relative_to

Method relative_to

tools/python-3.11.9-amd64/Lib/pathlib.py:703–734  ·  view source on GitHub ↗

Return the relative path to another path identified by the passed arguments. If the operation is not possible (because this is not a subpath of the other path), raise ValueError.

(self, *other)

Source from the content-addressed store, hash-verified

701 self._parts[:-1] + [name])
702
703 def relative_to(self, *other):
704 """Return the relative path to another path identified by the passed
705 arguments. If the operation is not possible (because this is not
706 a subpath of the other path), raise ValueError.
707 """
708 # For the purpose of this method, drive and root are considered
709 # separate parts, i.e.:
710 # Path('c:/').relative_to('c:') gives Path('/')
711 # Path('c:/').relative_to('/') raise ValueError
712 if not other:
713 raise TypeError("need at least one argument")
714 parts = self._parts
715 drv = self._drv
716 root = self._root
717 if root:
718 abs_parts = [drv, root] + parts[1:]
719 else:
720 abs_parts = parts
721 to_drv, to_root, to_parts = self._parse_args(other)
722 if to_root:
723 to_abs_parts = [to_drv, to_root] + to_parts[1:]
724 else:
725 to_abs_parts = to_parts
726 n = len(to_abs_parts)
727 cf = self._flavour.casefold_parts
728 if (root or drv) if n == 0 else cf(abs_parts[:n]) != cf(to_abs_parts):
729 formatted = self._format_parsed_parts(to_drv, to_root, to_parts)
730 raise ValueError("{!r} is not in the subpath of {!r}"
731 " OR one path is relative and the other is absolute."
732 .format(str(self), str(formatted)))
733 return self._from_parsed_parts('', root if n == 1 else '',
734 abs_parts[n:])
735
736 def is_relative_to(self, *other):
737 """Return True if the path is relative to another path or False.

Callers 4

is_relative_toMethod · 0.95
create_archiveFunction · 0.80
_normalize_outputMethod · 0.80

Calls 5

_parse_argsMethod · 0.95
_format_parsed_partsMethod · 0.95
_from_parsed_partsMethod · 0.95
strFunction · 0.85
formatMethod · 0.45

Tested by

no test coverage detected