]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
GH-72904: Add `glob.translate()` function (#106703)
authorBarney Gale <barney.gale@gmail.com>
Mon, 13 Nov 2023 17:15:56 +0000 (17:15 +0000)
committerGitHub <noreply@github.com>
Mon, 13 Nov 2023 17:15:56 +0000 (17:15 +0000)
commitcf67ebfb315ce36175f3d425249d7c6560f6d0d5
tree3007eaa7164eba027714b9752aecea60627e6de6
parentbabb787047e0f7807c8238d3b1a3128dac30bd5c
GH-72904: Add `glob.translate()` function (#106703)

Add `glob.translate()` function that converts a pathname with shell wildcards to a regular expression. The regular expression is used by pathlib to implement `match()` and `glob()`.

This function differs from `fnmatch.translate()` in that wildcards do not match path separators by default, and that a `*` pattern segment matches precisely one path segment. When *recursive* is set to true, `**` pattern segments match any number of path segments, and `**` cannot appear outside its own segment.

In pathlib, this change speeds up directory walking (because `_make_child_relpath()` does less work), makes path objects smaller (they don't need a `_lines` slot), and removes the need for some gnarly code.

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Doc/library/glob.rst
Doc/whatsnew/3.13.rst
Lib/fnmatch.py
Lib/glob.py
Lib/pathlib.py
Lib/test/test_glob.py
Misc/NEWS.d/next/Library/2023-07-13-00-24-52.gh-issue-72904.Yn5-j0.rst [new file with mode: 0644]