Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posixpath.commonpath: Check for empty iterables broken #114709

Closed
srittau opened this issue Jan 29, 2024 · 3 comments
Closed

posixpath.commonpath: Check for empty iterables broken #114709

srittau opened this issue Jan 29, 2024 · 3 comments
Labels
type-feature A feature request or enhancement

Comments

@srittau
Copy link
Contributor

srittau commented Jan 29, 2024

Bug report

Bug description:

This came up in python/typeshed#11310: When passing an empty sequence to commonpath(), a ValueError is raised with an appropriate error message. When an "empty" iterable is passed, an IndexError is raised instead, although iterables otherwise work fine:

from posixpath import commonpath

commonpath([])  # -> ValueError: commonpath() arg is an empty sequence
commonpath(iter([]))  # -> IndexError: tuple index out of range

The fix is trivial, I'll send a PR. Technically this is an API change, though, although the old API is unexpected.

CPython versions tested on:

3.11, 3.12

Operating systems tested on:

Linux

Linked PRs

@srittau srittau added the type-bug An unexpected behavior, bug, or error label Jan 29, 2024
@serhiy-storchaka
Copy link
Member

It did not supported arbitrary iterables initially, it only worked with sequences. Then in 3.6 it started working with non-empty iterables by accident, but it was not intentional change, it was an implementation detail.

Accepting an arbitrary iterable is a new feature. This change can only go in future 3.13.

@serhiy-storchaka serhiy-storchaka added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Jan 29, 2024
hauntsaninja pushed a commit that referenced this issue Feb 18, 2024
Fix the exceptions raised by posixpath.commonpath

Raise ValueError, not IndexError when passed an empty iterable. Raise
TypeError, not ValueError when passed None.
@serhiy-storchaka
Copy link
Member

Please revert the change in versionchanged:: 3.6 and add versionchanged:: 3.13.

@hauntsaninja
Copy link
Contributor

hauntsaninja commented Feb 18, 2024

Thanks, done in #115639

woodruffw pushed a commit to woodruffw-forks/cpython that referenced this issue Mar 4, 2024
…n#114710)

Fix the exceptions raised by posixpath.commonpath

Raise ValueError, not IndexError when passed an empty iterable. Raise
TypeError, not ValueError when passed None.
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this issue Mar 4, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
…n#114710)

Fix the exceptions raised by posixpath.commonpath

Raise ValueError, not IndexError when passed an empty iterable. Raise
TypeError, not ValueError when passed None.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants