[issue23082] pathlib relative_to() can give confusing error message

Sadhana Srinivasan report at bugs.python.org
Wed Apr 15 19:13:58 EDT 2020


Sadhana Srinivasan <sadhanasrinivasan at pm.me> added the comment:

I'll work on this. 

I tried to come up with a single error message but having two different error messages seems like a better idea to me. One for when the path isn't a subpath and one for when absolute and relative paths are mixed. Basically to explain this:

>>> Path("/Users/rotuna/Documents/cpython/Libs").relative_to(Path("./Libs"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/rotuna/Documents/cpython/Lib/pathlib.py", line 907, in relative_to
    raise ValueError("{!r} is not a subpath of{!r}. NOTE: If this is not true, use absolute paths"
ValueError: '/Users/rotuna/Documents/cpython/Libs' does not start with 'Libs'

----------
nosy: +rotuna

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue23082>
_______________________________________


More information about the Python-bugs-list mailing list