From a9bf9b6d3b851de1da3f46800dc2906a72f5300f Mon Sep 17 00:00:00 2001 From: Nineteendo Date: Tue, 9 Apr 2024 08:02:50 +0200 Subject: [PATCH] replace startswith with slice comparison --- Lib/posixpath.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 16b8d9091c5a84..000fe70e41807a 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -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] @@ -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)