mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
GH-73435: Implement recursive wildcards in pathlib.PurePath.match() (#101398)
`PurePath.match()` now handles the `**` wildcard as in `Path.glob()`, i.e. it matches any number of path segments. We now compile a `re.Pattern` object for the entire pattern. This is made more difficult by `fnmatch` not treating directory separators as special when evaluating wildcards (`*`, `?`, etc), and so we arrange the path parts onto separate *lines* in a string, and ensure we don't set `re.DOTALL`. Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
4c770617c0
commit
49f90ba1ea
5 changed files with 123 additions and 15 deletions
|
|
@ -569,6 +569,13 @@ Pure paths provide the following methods and properties:
|
|||
>>> PurePath('a/b.py').match('/*.py')
|
||||
False
|
||||
|
||||
The *pattern* may be another path object; this speeds up matching the same
|
||||
pattern against multiple files::
|
||||
|
||||
>>> pattern = PurePath('*.py')
|
||||
>>> PurePath('a/b.py').match(pattern)
|
||||
True
|
||||
|
||||
As with other methods, case-sensitivity follows platform defaults::
|
||||
|
||||
>>> PurePosixPath('b.py').match('*.PY')
|
||||
|
|
@ -581,6 +588,10 @@ Pure paths provide the following methods and properties:
|
|||
.. versionadded:: 3.12
|
||||
The *case_sensitive* argument.
|
||||
|
||||
.. versionchanged:: 3.13
|
||||
Support for the recursive wildcard "``**``" was added. In previous
|
||||
versions, it acted like the non-recursive wildcard "``*``".
|
||||
|
||||
|
||||
.. method:: PurePath.relative_to(other, walk_up=False)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue