Skip to content

posixpath.commonpath: Check for empty iterables broken #114709

Closed

Description

@srittau

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

Activity

  1. serhiy-storchaka commented on Jan 29, 2024

    @serhiy-storchaka
    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.

  2. added
    type-featureA feature request or enhancement
    and removed
    type-bugAn unexpected behavior, bug, or error
    on Jan 29, 2024
  3. added a commit that references this issue on Feb 18, 2024
  4. serhiy-storchaka commented on Feb 18, 2024

    @serhiy-storchaka
    Member

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

  5. added 2 commits that reference this issue on Feb 18, 2024
  6. hauntsaninja commented on Feb 18, 2024

    @hauntsaninja
    Contributor

    Thanks, done in #115639

  7. added 2 commits that reference this issue on Mar 4, 2024
  8. added 2 commits that reference this issue on Apr 17, 2024
  9. added 2 commits that reference this issue on Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions