Unipath icon indicating copy to clipboard operation
Unipath copied to clipboard

Bug in rel_path_to()?

Open 1pakch opened this issue 10 years ago • 0 comments

I find Path.rel_path_to() method to be quite confusing. Consider the following example:

In [27]: %paste
from unipath import Path
p1 = Path('/a/b')
p2 = Path('/a/b/c/d')
print p1.rel_path_to(p2)

## -- End pasted text --
b/c/d
..

I do not quite understand why the first call returns b/c/d I would expect that the relative path of /a/b/c/d/ w.r.t. a/b is c/d. Indeed this is what pathlib yields:

In [39]: %paste
from pathlib2 import Path
p1 = Path('/a/b')
p2 = Path('/a/b/c/d')
print p2.relative_to(p1)

## -- End pasted text --
c/d

Note that the calling convention is also different: p2.relative_to(p1) is arguably more intuitive compared to p1.rel_path_to(p2).

1pakch avatar Mar 10 '15 12:03 1pakch