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

Julien Palard julien at palard.fr
Tue Dec 25 17:23:37 EST 2018


Hi,

Thanks for reporting, this is due to the resolution of https://bugs.python.org/issue19717, I opened a PR to explicitly tell about it in the documentation: https://github.com/python/cpython/pull/11316

Can you proofread it?

Bests,
--
Julien Palard
https://mdk.fr

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Thursday 13 December 2018 10:54, Laurens Duijvesteijn <laurens at channable.com> wrote:

> 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/20181225/6c645d97/attachment-0001.html>


More information about the docs mailing list