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: Builtin `abs(Path)` should return `Path.absolute()`.
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: pitrou Nosy List: brandtbucher, pitrou
Priority: normal Keywords: patch

Created on 2018-09-09 15:47 by brandtbucher, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 9128 closed brandtbucher, 2018-09-09 15:48
Messages (3)
msg324890 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2018-09-09 15:47
This complements the current Path behavior that overrides division operators for path joining, in that it makes manually-constructed paths easier to form and arguably more readable.

Before:

p = Path("some", "relative", "path")
q = p.absolute() / "some" / "further" / "path"

After:

p = Path("some", "relative", "path")
q = abs(p) / "some" / "further" / "path"
msg324894 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2018-09-09 17:13
Hmm, thanks for taking the time of proposing this and submitting a PR, but no.  The documentation for `abs()` states:
"""
Return the absolute value of a number. The argument may be an integer or a floating point number. If the argument is a complex number, its magnitude is returned.
"""

This is all about numbers. Not about filesystem paths or any other kind of object. It's true that Path overrides the "division" operator, but that's an exception meant to make it easy to write a very common operation on paths (path joining), and because some people felt it looked pleasantly like the standard Unix path separator (it wasn't the initial choice, by the way).  No such argument applies in favour of abs(Path).

Moreover, Path.resolve() is strongly recommended over Path.absolute(), which currently isn't even exposed in the docs (though it seems that doesn't prevent people from actually using it ;-)).
msg324895 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2018-09-09 17:19
That all makes sense. Thanks for the quick response!
History
Date User Action Args
2022-04-11 14:59:05adminsetgithub: 78795
2018-09-09 17:19:46brandtbuchersetmessages: + msg324895
2018-09-09 17:13:15pitrousetstatus: open -> closed
resolution: rejected
stage: patch review -> resolved
2018-09-09 17:13:04pitrousetmessages: + msg324894
2018-09-09 17:05:18pitrousettitle: Builtin `abs(Path)` returns `Path.absolute()`. -> Builtin `abs(Path)` should return `Path.absolute()`.
2018-09-09 17:04:41rhettingersetassignee: pitrou

nosy: + pitrou
2018-09-09 15:48:17brandtbuchersetkeywords: + patch
stage: patch review
pull_requests: + pull_request8581
2018-09-09 15:47:39brandtbuchercreate