GH-79634: Accept path-like objects as pathlib glob patterns. (#114017)

Allow `os.PathLike` objects to be passed as patterns to `pathlib.Path.glob()` and `rglob()`. (It's already possible to use them in `PurePath.match()`)

While we're in the area:

- Allow empty glob patterns in `PathBase` (but not `Path`)
- Speed up globbing in `PathBase` by generating paths with trailing slashes only as a final step, rather than for every intermediate directory.
- Simplify and speed up handling of rare patterns involving both `**` and `..` segments.
This commit is contained in:
Barney Gale 2024-01-20 02:10:25 +00:00 committed by GitHub
parent 681e9e85a2
commit 6313cdde58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 115 additions and 72 deletions

View file

@ -1036,6 +1036,9 @@ call fails (for example because the path doesn't exist).
future Python release, patterns with this ending will match both files
and directories. Add a trailing slash to match only directories.
.. versionchanged:: 3.13
The *pattern* parameter accepts a :term:`path-like object`.
.. method:: Path.group(*, follow_symlinks=True)
Return the name of the group owning the file. :exc:`KeyError` is raised
@ -1498,6 +1501,9 @@ call fails (for example because the path doesn't exist).
.. versionchanged:: 3.13
The *follow_symlinks* parameter was added.
.. versionchanged:: 3.13
The *pattern* parameter accepts a :term:`path-like object`.
.. method:: Path.rmdir()
Remove this directory. The directory must be empty.