compat.py 360 B

1234567891011121314
  1. from pathlib import Path
  2. def is_relative_to(relpath: Path, otherpath: Path) -> bool:
  3. # is_relative_to was only added to Path in Python 3.9
  4. if hasattr(relpath, "is_relative_to"):
  5. return relpath.is_relative_to(otherpath)
  6. try:
  7. relpath.relative_to(otherpath)
  8. except ValueError:
  9. return False
  10. else:
  11. return True