Skip to content

Commit b848b94

Browse files
authored
gh-117641: Improve the perfornance of posixpath.commonpath() (#117652)
1 parent 6078f20 commit b848b94

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

Lib/posixpath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ def commonpath(paths):
550550
split_paths = [path.split(sep) for path in paths]
551551

552552
try:
553-
isabs, = set(p[:1] == sep for p in paths)
553+
isabs, = {p.startswith(sep) for p in paths}
554554
except ValueError:
555555
raise ValueError("Can't mix absolute and relative paths") from None
556556

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Speedup :func:`os.path.commonpath` on Unix.

0 commit comments

Comments
 (0)