]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
GH-73435: Add `pathlib.PurePath.full_match()` (#114350)
authorBarney Gale <barney.gale@gmail.com>
Fri, 26 Jan 2024 01:12:46 +0000 (01:12 +0000)
committerGitHub <noreply@github.com>
Fri, 26 Jan 2024 01:12:46 +0000 (01:12 +0000)
commitb69548a0f52418b8a2cf7c7a885fdd7d3bfb1b0b
tree9f28d0deaeeb3d31f479cd31d255244ebd700f98
parent841eacd07646e643f87d7f063106633a25315910
GH-73435: Add `pathlib.PurePath.full_match()` (#114350)

In 49f90ba we added support for the recursive wildcard `**` in
`pathlib.PurePath.match()`. This should allow arbitrary prefix and suffix
matching, like `p.match('foo/**')` or `p.match('**/foo')`, but there's a
problem: for relative patterns only, `match()` implicitly inserts a `**`
token on the left hand side, causing all patterns to match from the right.
As a result, it's impossible to match relative patterns from the left:
`PurePath('foo/bar').match('bar/**')` is true!

This commit reverts the changes to `match()`, and instead adds a new
`full_match()` method that:

- Allows empty patterns
- Supports the recursive wildcard `**`
- Matches the *entire* path when given a relative pattern
Doc/library/glob.rst
Doc/library/pathlib.rst
Doc/whatsnew/3.13.rst
Lib/pathlib/__init__.py
Lib/pathlib/_abc.py
Lib/test/test_pathlib/test_pathlib_abc.py