Repository navigation
Path.relative_to() taking multiple arguments could be better documented #78707
Description
Activity
Currently, the docs for Path.relative_to read
PurePath.relative_to(*other) Compute a version of this path relative to the path represented by other. If it’s impossible, ValueError is raised: (examples follow)
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).- added3.9 (EOL)end of lifeend of life3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixesand removed3.7 (EOL)end of lifeend of life
on Jan 19, 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.Reacted by Jelle ZijlstraAgree 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.
Reacted by Barney Gale- added a commit that references this issue
on Dec 17, 2022 - added a commit that references this issue
on Dec 18, 2022 - added a commit that references this issue
on Dec 19, 2022 - added 4 commits that reference this issue
on May 8, 2024 - added a commit that references this issue
on Jul 17, 2024
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
PurePath.[is_]relative_to()#94469pathlib.PurePath.[is_]relative_to()arguments #118780