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

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

Closed
barneygale opened this issue Mar 5, 2024 · 1 comment
Closed
Labels
type-bug An unexpected behavior, bug, or error

Comments

@barneygale
Copy link
Contributor

barneygale commented Mar 5, 2024

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

@barneygale barneygale added the type-bug An unexpected behavior, bug, or error label Mar 5, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Mar 5, 2024
Stop raising `ValueError` from `glob.translate()` when a `**` sub-string
appears in a non-recursive pattern segment. This matches `glob.glob()`
behaviour.
@terryjreedy
Copy link
Member

Seems sensible to me.

barneygale added a commit to barneygale/cpython that referenced this issue Mar 5, 2024
Stop raising `ValueError` from `glob.translate()` when a `**` sub-string
appears in a non-recursive pattern segment. This matches `glob.glob()`
behaviour.
barneygale added a commit that referenced this issue Mar 17, 2024
Stop raising `ValueError` from `glob.translate()` when a `**` sub-string
appears in a non-recursive pattern segment. This matches `glob.glob()`
behaviour.
vstinner pushed a commit to vstinner/cpython that referenced this issue Mar 20, 2024
…ython#116378)

Stop raising `ValueError` from `glob.translate()` when a `**` sub-string
appears in a non-recursive pattern segment. This matches `glob.glob()`
behaviour.
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 25, 2024
…ython#116378)

Stop raising `ValueError` from `glob.translate()` when a `**` sub-string
appears in a non-recursive pattern segment. This matches `glob.glob()`
behaviour.
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
…ython#116378)

Stop raising `ValueError` from `glob.translate()` when a `**` sub-string
appears in a non-recursive pattern segment. This matches `glob.glob()`
behaviour.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants