[New-bugs-announce] [issue20012] Allow Path.relative_to() to accept non-ancestor paths
Alexander Boyd
report at bugs.python.org
Wed Dec 18 07:10:11 CET 2013
New submission from Alexander Boyd:
pathlib.Path.relative_to() blows up when given a path that's not an ancestor of the path on which relative_to is being called:
>>> pathlib.Path("/usr/bin").relative_to("/etc")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pathlib.py", line 822, in relative_to
.format(str(self), str(formatted)))
ValueError: '/usr/bin' does not start with '/etc'
The equivalent with posixpath.relpath (or ntpath.relpath) works just fine:
>>> posixpath.relpath("/usr/bin", "/etc")
'../usr/bin'
It'd be nice if Path.relative_to supported this type of usage.
----------
components: Library (Lib)
messages: 206497
nosy: javawizard, pitrou
priority: normal
severity: normal
status: open
title: Allow Path.relative_to() to accept non-ancestor paths
type: enhancement
versions: Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20012>
_______________________________________
More information about the New-bugs-announce
mailing list