diff --git a/Lib/posixpath.py b/Lib/posixpath.py index dd29fbb1614aa8..740f18646df3f2 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -547,7 +547,7 @@ def commonpath(paths): split_paths = [path.split(sep) for path in paths] try: - isabs, = set(p[:1] == sep for p in paths) + isabs, = {p.startswith(sep) for p in paths} except ValueError: raise ValueError("Can't mix absolute and relative paths") from None diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-08-19-30-38.gh-issue-117641.oaBGSJ.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-19-30-38.gh-issue-117641.oaBGSJ.rst new file mode 100644 index 00000000000000..e313c133b72173 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-19-30-38.gh-issue-117641.oaBGSJ.rst @@ -0,0 +1 @@ +Speedup :func:`os.path.commonpath` on Unix.