classification
Title: pathlib relative_to behaviour change
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: duplicate
Dependencies: Superseder: pathlib's relative_to should behave like os.path.relpath
View: 40358
Assigned To: Nosy List: armins.bagrats, barneygale
Priority: normal Keywords:

Created on 2020-11-01 15:48 by armins.bagrats, last changed 2021-06-23 10:41 by serhiy.storchaka. This issue is now closed.

Messages (3)
msg380148 - (view) Author: Armins Stepanjans (armins.bagrats) Date: 2020-11-01 15:48
In the docs (https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.relative_to) PurePath.relative_to() is specified to fail for arguments that are not on the original path (e.g. Path('/ham/beans').relative_to(Path('/spam'))).

I believe it would be useful to extend the behaviour of relative_to so that it handles the case above. For example, I would expect Path('/ham/beans').relative_to(Path('/spam')) to return Path('../ham/beans').

If this sounds like a useful change I'd be happy to make a PR for it.
msg393774 - (view) Author: Barney Gale (barneygale) * Date: 2021-05-17 00:19
That does sound pretty useful! I'd be happy to review a PR though I'm not a core dev.
msg393776 - (view) Author: Barney Gale (barneygale) * Date: 2021-05-17 00:54
In fact, I think this is a duplicate of issue40358, which has an open PR against it.
History
Date User Action Args
2021-06-23 10:41:51serhiy.storchakasetstatus: open -> closed
superseder: pathlib's relative_to should behave like os.path.relpath
resolution: duplicate
stage: resolved
2021-05-17 00:54:45barneygalesetmessages: + msg393776
2021-05-17 00:19:20barneygalesetnosy: + barneygale
messages: + msg393774
2020-11-01 15:48:23armins.bagratscreate