You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Path.relative_to() taking multiple arguments could be better documented #78707
It's a bit confusing why other is a star-args, especially as no example actually passes more than one argument to relative_to.
The docstring is a tiny bit clearer:
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.
Effectively, a Path is constructed from all *other args and used as base for the computation of the relative path. It looks a bit like a misfeature to me, but at least it could be better documented (e.g. by adding Path("/tmp/foo/bar").relative_to("/tmp", "foo") == Path("bar") as example in the docs).
Activity
anntzer commentedon Aug 28, 2018
Currently, the docs for Path.relative_to read
It's a bit confusing why other is a star-args, especially as no example actually passes more than one argument to relative_to.
The docstring is a tiny bit clearer:
Effectively, a Path is constructed from all *other args and used as base for the computation of the relative path. It looks a bit like a misfeature to me, but at least it could be better documented (e.g. by adding
Path("/tmp/foo/bar").relative_to("/tmp", "foo") == Path("bar")as example in the docs).barneygale commentedon May 2, 2022
I think this is a mis-feature and we should look at deprecating + removing it, rather than documenting it.
Consider that pathlib has many other methods that accept a single other path, like
rename(),replace(),symlink_to()andhardlink_to().The only methods that should support
*argsshould bejoinpath()and thePurePathinitialiser IMO.JelleZijlstra commentedon May 2, 2022
Agree that this is a misfeature. We'll have to go through a deprecation cycle to remove it though, since it's at least kind of documented.
Merge branch 'main' into pythongh-78707-pathlib-relative-to-arguments
gh-78707: deprecate passing >1 argument to `PurePath.[is_]relative_to…
Merge remote-tracking branch 'origin/main' into bpo_34697
Merge branch 'main' into fastmock
pythonGH-78707: Drop deprecated `pathlib.PurePath.[is_]relative_to()`…
Merge branch 'main' into pythongh-78707-remove
Merge branch 'main' into pythongh-78707-remove
GH-78707: Drop deprecated `pathlib.PurePath.[is_]relative_to()` argum…
pythonGH-78707: Drop deprecated `pathlib.PurePath.[is_]relative_to()`…