[issue40358] pathlib's relative_to should behave like os.path.relpath

Eryk Sun report at bugs.python.org
Wed Apr 22 15:50:21 EDT 2020


Eryk Sun <eryksun at gmail.com> added the comment:

Note that the implementation of relpath is pure and thus assumes it's working with existing, resolved paths (i.e. "the filesystem is not accessed to confirm the existence or nature of path or start"). For example:

    >>> os.path.relpath('/some/thing', '/symlink')
    '../some/thing'

If "symlink" targets "/spam/eggs/foo", then the resolved path would be "/spam/eggs/some/thing" instead of "/some/thing". Maybe the relative_to method should default to a `strict` mode that raises ValueError on ambiguous cases that depend on the "existence or nature" of the paths. I think the current implementation is strict.

----------
nosy: +eryksun

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


More information about the Python-bugs-list mailing list