aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/ntpath.py
diff options
context:
space:
mode:
authorNice Zombies <nineteendo19d0@gmail.com>2024-03-28 22:20:08 +0100
committerGitHub <noreply@github.com>2024-03-28 21:20:08 +0000
commit14f1ca7d5363386163839b31ce987423daecc3de (patch)
tree6c074f58ddb90dc77298051241c0f505e4823de4 /Lib/ntpath.py
parent18cf239e39e25e6cef50ecbb7f197a82f8920ff5 (diff)
downloadcpython-14f1ca7d5363386163839b31ce987423daecc3de.tar.gz
cpython-14f1ca7d5363386163839b31ce987423daecc3de.zip
gh-117335: Handle non-iterables for `ntpath.commonpath` (GH-117336)
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r--Lib/ntpath.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index f1c48ecd1e5..ecfc7d48dbb 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -831,23 +831,22 @@ def relpath(path, start=None):
raise
-# Return the longest common sub-path of the sequence of paths given as input.
+# Return the longest common sub-path of the iterable of paths given as input.
# The function is case-insensitive and 'separator-insensitive', i.e. if the
# only difference between two paths is the use of '\' versus '/' as separator,
# they are deemed to be equal.
#
# However, the returned path will have the standard '\' separator (even if the
# given paths had the alternative '/' separator) and will have the case of the
-# first path given in the sequence. Additionally, any trailing separator is
+# first path given in the iterable. Additionally, any trailing separator is
# stripped from the returned path.
def commonpath(paths):
- """Given a sequence of path names, returns the longest common sub-path."""
-
+ """Given an iterable of path names, returns the longest common sub-path."""
+ paths = tuple(map(os.fspath, paths))
if not paths:
- raise ValueError('commonpath() arg is an empty sequence')
+ raise ValueError('commonpath() arg is an empty iterable')
- paths = tuple(map(os.fspath, paths))
if isinstance(paths[0], bytes):
sep = b'\\'
altsep = b'/'