This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pathlib.Path.resolve incorrect os.path equivalent
Type: behavior Stage: patch review
Components: Documentation Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Jeffrey.Kintscher, Jendrik Weise, docs@python
Priority: normal Keywords: patch

Created on 2020-07-21 10:31 by Jendrik Weise, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
bpo-41537-test.py Jeffrey.Kintscher, 2020-07-22 22:39 script that illustrates differences between how Path.resolve(), os.path.abspath(), and os.path.realpath() handle symlinks
Pull Requests
URL Status Linked Edit
PR 21596 open Jeffrey.Kintscher, 2020-07-23 01:08
Messages (2)
msg374060 - (view) Author: Jendrik Weise (Jendrik Weise) Date: 2020-07-21 10:31
According to the table at the bottom of the pathlib documentation Path.resolve() is equivalent to os.path.abspath(path). In contrast to the latter Path.resolve() does follow symlinks though, making it more similar to os.path.realpath(path).
msg374115 - (view) Author: Jeffrey Kintscher (Jeffrey.Kintscher) * Date: 2020-07-22 22:39
I uploaded a script illustrating the differences between how Path.resolve(), os.path.abspath(), and os.path.realpath() handle symlinks.  As noted by Jendrik, Path.resolve() and os.path.realpath() both resolve symlinks, while os.path.abspath() does not.  The documentation needs to be updated.  I will generate a pull request.

Example run on the master branch:

python version:
3.9.0a0 (heads/master-dirty:f69d5c6198, Jul 16 2019, 12:38:41) 
[Clang 10.0.1 (clang-1001.0.46.4)]
----
tdir1: /var/folders/w7/mxt827716xs7_3wbk3mqwd3h0000gn/T/tmpyj7juuca/foo1
creating tdir1
tdir2: /var/folders/w7/mxt827716xs7_3wbk3mqwd3h0000gn/T/tmpyj7juuca/foo2
creating tdir2 as symlink to tdir1
Path(tdir1).resolve(): /private/var/folders/w7/mxt827716xs7_3wbk3mqwd3h0000gn/T/tmpyj7juuca/foo1
Path(tdir2).resolve(): /private/var/folders/w7/mxt827716xs7_3wbk3mqwd3h0000gn/T/tmpyj7juuca/foo1
os.path.abspath(tdir1): /var/folders/w7/mxt827716xs7_3wbk3mqwd3h0000gn/T/tmpyj7juuca/foo1
os.path.abspath(tdir2): /var/folders/w7/mxt827716xs7_3wbk3mqwd3h0000gn/T/tmpyj7juuca/foo2
os.path.realpath(tdir1): /private/var/folders/w7/mxt827716xs7_3wbk3mqwd3h0000gn/T/tmpyj7juuca/foo1
os.path.realpath(tdir2): /private/var/folders/w7/mxt827716xs7_3wbk3mqwd3h0000gn/T/tmpyj7juuca/foo1
History
Date User Action Args
2022-04-11 14:59:33adminsetgithub: 85529
2020-07-23 01:08:11Jeffrey.Kintschersetkeywords: + patch
stage: patch review
pull_requests: + pull_request20735
2020-07-22 22:39:39Jeffrey.Kintschersetfiles: + bpo-41537-test.py

messages: + msg374115
2020-07-22 21:12:12Jeffrey.Kintschersetnosy: + Jeffrey.Kintscher
2020-07-21 10:31:29Jendrik Weisecreate