Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-114709: Fix exceptions raised by posixpath.commonpath#114710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
hauntsaninja merged 1 commit intopython:mainfromsrittau:commonpath-iter
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
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
4 changes: 2 additions & 2 deletionsDoc/library/os.path.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -79,7 +79,7 @@ the :mod:`glob` module.)

..function::commonpath(paths)

Return the longest common sub-path of each pathname in thesequence
Return the longest common sub-path of each pathname in theiterable
*paths*. Raise:exc:`ValueError` if *paths* contain both absolute
and relative pathnames, the *paths* are on the different drives or
if *paths* is empty. Unlike:func:`commonprefix`, this returns a
Expand All@@ -90,7 +90,7 @@ the :mod:`glob` module.)
..versionadded::3.5

..versionchanged::3.6
Acceptsa sequence of:term:`path-like objects <path-like object>`.
Acceptsan iterable of:term:`path-like objects <path-like object>`.


..function::commonprefix(list)
Expand Down
3 changes: 2 additions & 1 deletionLib/posixpath.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -546,10 +546,11 @@ def relpath(path, start=None):
defcommonpath(paths):
"""Given a sequence of path names, returns the longest common sub-path."""

paths=tuple(map(os.fspath,paths))

ifnotpaths:
raiseValueError('commonpath() arg is an empty sequence')

paths=tuple(map(os.fspath,paths))
ifisinstance(paths[0],bytes):
sep=b'/'
curdir=b'.'
Expand Down
2 changes: 2 additions & 0 deletionsLib/test/test_posixpath.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -703,7 +703,9 @@ def check_error(exc, paths):
self.assertRaises(exc,posixpath.commonpath,
[os.fsencode(p)forpinpaths])

self.assertRaises(TypeError,posixpath.commonpath,None)
self.assertRaises(ValueError,posixpath.commonpath, [])
self.assertRaises(ValueError,posixpath.commonpath,iter([]))
check_error(ValueError, ['/usr','usr'])
check_error(ValueError, ['usr','/usr'])

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
:func:`posixpath.commonpath()` now raises a:exc:`ValueError` exception when
passed an empty iterable. Previously,:exc:`IndexError` was raised.

:func:`posixpath.commonpath()` now raises a:exc:`TypeError` exception when
passed ``None``. Previously,:exc:`ValueError` was raised.

[8]ページ先頭

©2009-2025 Movatter.jp