Skip to content

glob.translate() rejects non-recursive pattern segments that include "**" #116377

Description

@barneygale

Bug report

Bug description:

glob.translate(recursive=True) (new in 3.13) rejects any pattern with a segment that includes **, unless ** is the entire segment. For example, translate('**a') is rejected but not translate('**')

Rejecting such segments is longstanding pathlib behaviour, but it has no precedent in the glob module -- glob.glob(recursive=True) happily accepts such segments.

>>> import glob
>>> glob.glob('**.py', recursive=True)
['blah.py']
>>> glob.translate('**.py', recursive=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    glob.translate('**.py', recursive=True)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/barney/projects/cpython/Lib/glob.py", line 304, in translate
    raise ValueError("Invalid pattern: '**' can only be an entire path component")
ValueError: Invalid pattern: '**' can only be an entire path component

translate() should treat these segments similar to glob(), and leave the pattern validation stuff to pathlib.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added a commit that references this issue on Mar 5, 2024
  2. terryjreedy commented on Mar 5, 2024

    @terryjreedy
    Member

    Seems sensible to me.

  3. added a commit that references this issue on Mar 5, 2024
  4. added a commit that references this issue on Mar 17, 2024
  5. added a commit that references this issue on Mar 20, 2024
  6. added a commit that references this issue on Mar 25, 2024
  7. added a commit that references this issue on Apr 17, 2024
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-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions