diff --git a/Lib/posixpath.py b/Lib/posixpath.py index b7fbdff20cac99..1075db13da8b6f 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -388,11 +388,17 @@ def abspath(path): """Return an absolute path.""" path = os.fspath(path) if isinstance(path, bytes): - if not path.startswith(b'/'): - path = join(os.getcwdb(), path) + sep = b'/' + curdir = b'.' + getcwd = os.getcwdb else: - if not path.startswith('/'): - path = join(os.getcwd(), path) + sep = '/' + curdir = '.' + getcwd = os.getcwd + if not path.startswith(sep): + if not path or path == curdir: + return getcwd() + path = join(getcwd(), path) return normpath(path) diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-08-15-04-51.gh-issue-117639.ca4N3t.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-15-04-51.gh-issue-117639.ca4N3t.rst new file mode 100644 index 00000000000000..fce709439c83e2 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-15-04-51.gh-issue-117639.ca4N3t.rst @@ -0,0 +1 @@ +Speedup :func:`os.path.abspath()` by up to 13% on Unix for "" & ".".