Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle errors for iterable
  • Loading branch information
nineteendo committed Mar 26, 2024
commit 26eac213196480b81551c654b6b2fd9e84888932
11 changes: 7 additions & 4 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,21 +538,24 @@ 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 paths are not normalized before comparing them (this is the
# responsibility of the caller). 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 a iterable of path names, returns the longest common sub-path."""
_, roots, tails = zip(*map(splitroot, paths))
if not roots:
raise ValueError('commonpath() arg is an empty sequence')
raise ValueError('commonpath() arg is an empty iterable')

try:
prefix = min(roots)
except (TypeError, AttributeError):
genericpath._check_arg_types('commonpath', *paths)
genericpath._check_arg_types('commonpath', *(
# Can't use paths, can be an iterable
root + tail for root, tail in zip(roots, tails)
))
raise

if not prefix and max(roots):
Expand Down