[docs] Path.resolve() unclear about backwards incompatibility

Laurens Duijvesteijn laurens at channable.com
Thu Dec 13 04:54:49 EST 2018


Hi,

The `Path.resolve()` method behaves differently on Python 3.5 vs Python 3.6.

The docs https://docs.python.org/3/library/pathlib.html#pathlib.Path.resolve
fail to mention this.

This is the behavior on 3.5:

```
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import Path
>>> p = Path('/var/../doesnotexist.txt')
>>> p.resolve()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/pathlib.py", line 1109, in resolve
    s = self._flavour.resolve(self)
  File "/usr/lib/python3.5/pathlib.py", line 330, in resolve
    return _resolve(base, str(path)) or sep
  File "/usr/lib/python3.5/pathlib.py", line 315, in _resolve
    target = accessor.readlink(newpath)
  File "/usr/lib/python3.5/pathlib.py", line 422, in readlink
    return os.readlink(path)
FileNotFoundError: [Errno 2] No such file or directory: '/doesnotexist.txt'
```

This is the behavior on 3.6:

```
Python 3.6.6 (default, Sep 12 2018, 18:26:19)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import Path
>>> p = Path('/var/../doesnotexist.txt')
>>> p.resolve()
PosixPath('/doesnotexist.txt')
```

I'd even say this change is a bug in the standard lib (if done on purpose,
it is not listed as a backwards incompatible change in the release notes,
didn't dig further).

The docs mention "New in version 3.6: The strict argument". IMO the docs
should also mention that before 3.5, this method would raise FileNotFound
by default.

Thanks and kind regards,
Laurens Duijvesteijn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20181213/16eaa165/attachment.html>


More information about the docs mailing list