[issue47161] pathlib method relative_to doesnt work with // in paths

2022-03-30 Thread Jan Bronicki


New submission from Jan Bronicki :

The `//` path should be equivalent to `/`, and in some ways, it does behave 
like that in pathlib. But in the `relative_to` method on a `Path` object, it 
does not work
This is causing our CI pipeline to fail. In the documentation here you can see 
`//` being properly processed:

https://docs.python.org/3/library/pathlib.html


```python
In [10]: x=Path("/Library/Video") ; x.relative_to(Path("/"))
Out[10]: PosixPath('Library/Video')

In [11]: x=Path("//Library/Video") ; x.relative_to(Path("/"))
---
ValueErrorTraceback (most recent call last)
Input In [11], in ()
> 1 x=Path("//Library/Video") ; x.relative_to(Path("/"))

File ~/.pyenv/versions/3.8.13/lib/python3.8/pathlib.py:908, in 
PurePath.relative_to(self, *other)
906 if (root or drv) if n == 0 else cf(abs_parts[:n]) != cf(to_abs_parts):
907 formatted = self._format_parsed_parts(to_drv, to_root, to_parts)
--> 908 raise ValueError("{!r} does not start with {!r}"
909  .format(str(self), str(formatted)))
910 return self._from_parsed_parts('', root if n == 1 else '',
911abs_parts[n:])

ValueError: '//Library/Video' does not start with '/'
```

--
components: Library (Lib)
messages: 416336
nosy: John15321
priority: normal
severity: normal
status: open
title: pathlib method relative_to doesnt work with // in paths
type: behavior
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue47161>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47161] pathlib method relative_to doesnt work with // in paths

2022-03-30 Thread Jan Bronicki


Jan Bronicki  added the comment:

But shouldn't it just work with `//` as a `/`? It seems like this is the 
behavior elsewhere. Sure I get that it cannot be done for 3.8. But the new 
error message implies that either `//` is not a subpath of `/` which it is, or 
that one is relative and the other is absolute, which is also false because 
both are absolutes

--

___
Python tracker 
<https://bugs.python.org/issue47161>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47161] pathlib method relative_to doesnt work with // in paths

2022-03-30 Thread Jan Bronicki


Jan Bronicki  added the comment:

Hmm..., I get it, but Im not gonna lie it's pretty confusing given that in 
other places `//` works as a substitute for `/`. Maybe it should be mentioned 
in the documentation?

--

___
Python tracker 
<https://bugs.python.org/issue47161>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com