From 78c202c1fc80bc79de2cc3399d7857b4a179b0a1 Mon Sep 17 00:00:00 2001 From: nineteendo Date: Mon, 8 Apr 2024 16:59:52 +0200 Subject: [PATCH 1/3] Special case for current dir in `posixpath.abspath()` --- Lib/posixpath.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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) From c22cdc580cf1aa20c72ebd5ea0063c664a0440d6 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:04:52 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2024-04-08-15-04-51.gh-issue-117639.ca4N3t.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-04-08-15-04-51.gh-issue-117639.ca4N3t.rst 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..e1581b8600636b --- /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 the current directory. From 5fefea0b0f3ec0137f0baa487e2979f484fee9b5 Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Tue, 9 Apr 2024 08:50:15 +0200 Subject: [PATCH 3/3] Update 2024-04-08-15-04-51.gh-issue-117639.ca4N3t.rst --- .../2024-04-08-15-04-51.gh-issue-117639.ca4N3t.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index e1581b8600636b..fce709439c83e2 100644 --- 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 @@ -1 +1 @@ -Speedup :func:`os.path.abspath()` by up to 13% on Unix for the current directory. +Speedup :func:`os.path.abspath()` by up to 13% on Unix for "" & ".".