aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/ntpath.py
diff options
context:
space:
mode:
authorNice Zombies <nineteendo19d0@gmail.com>2024-04-03 15:10:09 +0200
committerGitHub <noreply@github.com>2024-04-03 16:10:09 +0300
commit2ec6bb4111d2c03c1cac02b27c74beee7e5a2a05 (patch)
tree2192d2a4a743b0f261614d11f4a0706513636a0e /Lib/ntpath.py
parenta214f55b274df9782e78e99516a372e0b800162a (diff)
downloadcpython-2ec6bb4111d2c03c1cac02b27c74beee7e5a2a05.tar.gz
cpython-2ec6bb4111d2c03c1cac02b27c74beee7e5a2a05.zip
gh-117381: Improve error messages for ntpath.commonpath() (GH-117382)
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r--Lib/ntpath.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index 0650f14f89f..f9f6c78566e 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -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]