gh-117381: Improve error messages for ntpath.commonpath() (GH-117382)

This commit is contained in:
Nice Zombies 2024-04-03 15:10:09 +02:00 committed by GitHub
parent a214f55b27
commit 2ec6bb4111
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 50 additions and 49 deletions

View file

@ -857,9 +857,6 @@ def commonpath(paths):
drivesplits = [splitroot(p.replace(altsep, sep).lower()) for p in paths]
split_paths = [p.split(sep) for d, r, p in drivesplits]
if len({r for d, r, p in drivesplits}) != 1:
raise ValueError("Can't mix absolute and relative paths")
# Check that all drive letters or UNC paths match. The check is made only
# now otherwise type errors for mixing strings and bytes would not be
# caught.
@ -867,6 +864,12 @@ def commonpath(paths):
raise ValueError("Paths don't have the same drive")
drive, root, path = splitroot(paths[0].replace(altsep, sep))
if len({r for d, r, p in drivesplits}) != 1:
if drive:
raise ValueError("Can't mix absolute and relative paths")
else:
raise ValueError("Can't mix rooted and not-rooted paths")
common = path.split(sep)
common = [c for c in common if c and c != curdir]