Skip to content

Commit

Permalink
replace startswith with slice comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo committed Apr 9, 2024
1 parent a9a7161 commit a9bf9b6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def commonpath(paths):
try:
split_paths = [path.split(sep) for path in paths]

if len({p.startswith(sep) for p in paths}) != 1:
if len({p[:1] == sep for p in paths}) != 1:
raise ValueError("Can't mix absolute and relative paths")

split_paths = [[c for c in s if c and c != curdir] for s in split_paths]
Expand All @@ -570,7 +570,7 @@ def commonpath(paths):
common = s1[:i]
break

prefix = sep if paths[0].startswith(sep) else sep[:0]
prefix = sep if paths[0][:1] == sep else sep[:0]
return prefix + sep.join(common)
except (TypeError, AttributeError):
genericpath._check_arg_types('commonpath', *paths)
Expand Down

0 comments on commit a9bf9b6

Please sign in to comment.