mirror of
https://github.com/python/cpython.git
synced 2026-01-05 06:52:26 +00:00
By default, :meth:`pathlib.PurePath.relative_to` doesn't deal with paths that are not a direct prefix of the other, raising an exception in that instance. This change adds a *walk_up* parameter that can be set to allow for using ``..`` to calculate the relative path.
example:
```
>>> p = PurePosixPath('/etc/passwd')
>>> p.relative_to('/etc')
PurePosixPath('passwd')
>>> p.relative_to('/usr')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pathlib.py", line 940, in relative_to
raise ValueError(error_message.format(str(self), str(formatted)))
ValueError: '/etc/passwd' does not start with '/usr'
>>> p.relative_to('/usr', strict=False)
PurePosixPath('../etc/passwd')
```
https://bugs.python.org/issue40358
Automerge-Triggered-By: GH:brettcannon
|
||
|---|---|---|
| .. | ||
| 2.0.rst | ||
| 2.1.rst | ||
| 2.2.rst | ||
| 2.3.rst | ||
| 2.4.rst | ||
| 2.5.rst | ||
| 2.6.rst | ||
| 2.7.rst | ||
| 3.0.rst | ||
| 3.1.rst | ||
| 3.2.rst | ||
| 3.3.rst | ||
| 3.4.rst | ||
| 3.5.rst | ||
| 3.6.rst | ||
| 3.7.rst | ||
| 3.8.rst | ||
| 3.9.rst | ||
| 3.10.rst | ||
| 3.11.rst | ||
| 3.12.rst | ||
| changelog.rst | ||
| index.rst | ||