[issue34614] Builtin `abs(Path)` should return `Path.absolute()`.

Antoine Pitrou report at bugs.python.org
Sun Sep 9 13:13:04 EDT 2018


Antoine Pitrou <pitrou at free.fr> added the comment:

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 ;-)).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34614>
_______________________________________


More information about the Python-bugs-list mailing list