-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
GH-101112: Provide pattern overview for Path.glob
#101223
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -548,8 +548,9 @@ Pure paths provide the following methods and properties: | |||||
|
||||||
.. method:: PurePath.match(pattern, *, case_sensitive=None) | ||||||
|
||||||
Match this path against the provided glob-style pattern. Return ``True`` | ||||||
if matching is successful, ``False`` otherwise. | ||||||
Match this path against the provided glob-style pattern. The pattern uses | ||||||
the same format as in :func:`Path.glob`. Return ``True`` if matching is | ||||||
successful, ``False`` otherwise. | ||||||
|
||||||
If *pattern* is relative, the path can be either relative or absolute, | ||||||
and matching is done from the right:: | ||||||
|
@@ -906,7 +907,7 @@ call fails (for example because the path doesn't exist). | |||||
>>> sorted(Path('.').glob('*/*.py')) | ||||||
[PosixPath('docs/conf.py')] | ||||||
|
||||||
Patterns are the same as for :mod:`fnmatch`, with the addition of "``**``" | ||||||
Pattern segments are the same as for :mod:`fnmatch`, with the addition of "``**``" | ||||||
which means "this directory and all subdirectories, recursively". In other | ||||||
words, it enables recursive globbing:: | ||||||
|
||||||
|
@@ -917,6 +918,22 @@ call fails (for example because the path doesn't exist). | |||||
PosixPath('setup.py'), | ||||||
PosixPath('test_pathlib.py')] | ||||||
|
||||||
The following wildcards are available: | ||||||
|
||||||
+------------+----------------------------------------------------------+ | ||||||
| Pattern | Meaning | | ||||||
+============+==========================================================+ | ||||||
| ``**`` | matches any number of nested directories | | ||||||
+------------+----------------------------------------------------------+ | ||||||
| ``*`` | matches any part of a file or directory name | | ||||||
+------------+----------------------------------------------------------+ | ||||||
| ``?`` | matches any single character in a file or directory name | | ||||||
+------------+----------------------------------------------------------+ | ||||||
| ``[seq]`` | matches any character in seq | | ||||||
+------------+----------------------------------------------------------+ | ||||||
| ``[!seq]`` | matches any character not in seq | | ||||||
+------------+----------------------------------------------------------+ | ||||||
|
||||||
By default, or when the *case_sensitive* keyword-only argument is set to | ||||||
``None``, this method matches paths using platform-specific casing rules: | ||||||
typically, case-sensitive on POSIX, and case-insensitive on Windows. | ||||||
|
@@ -1331,8 +1348,7 @@ call fails (for example because the path doesn't exist). | |||||
.. method:: Path.rglob(pattern, *, case_sensitive=None, follow_symlinks=None) | ||||||
|
||||||
Glob the given relative *pattern* recursively. This is like calling | ||||||
:func:`Path.glob` with "``**/``" added in front of the *pattern*, where | ||||||
*patterns* are the same as for :mod:`fnmatch`:: | ||||||
:func:`Path.glob` with "``**/``" added in front of the *pattern*:: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
>>> sorted(Path().rglob("*.py")) | ||||||
[PosixPath('build/lib/pathlib.py'), | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.