Skip to content
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

Path.rglob -> documentation does not specify what pattern is #101112

Closed
jugmac00 opened this issue Jan 17, 2023 · 6 comments
Closed

Path.rglob -> documentation does not specify what pattern is #101112

jugmac00 opened this issue Jan 17, 2023 · 6 comments
Labels
docs Documentation in the Doc dir topic-pathlib

Comments

@jugmac00
Copy link
Contributor

jugmac00 commented Jan 17, 2023

Documentation

Today I came across Path.rglob in our codebase.

I went to https://docs.python.org/3/library/pathlib.html#pathlib.Path.rglob and tried to find out what pattern actually is. While the current documentation links to Path.glob(), I would like to add a note similar you can find at https://docs.python.org/3/library/pathlib.html#pathlib.Path.glob, ie

Patterns are the same as for fnmatch

Would a PR be welcome to add this kind of information?

Linked PRs

@jugmac00 jugmac00 added the docs Documentation in the Doc dir label Jan 17, 2023
jugmac00 added a commit to jugmac00/cpython that referenced this issue Jan 18, 2023
The documentation for `rglob` did not mention what `pattern` actually
is.

Mentioning and linking to `fnmatch` makes this explicit, as the
documentation for `fnmatch` both shows the syntax and some explanation.
@barneygale
Copy link
Contributor

The documentation for glob() is wrong - the pattern is interpreted differently by fnmatch. In fnmatch(), the * wildcard can match directory separators, but in glob() it can't. The ** wildcard matches separators in glob(), but it can only appear in its own path segment.

It should probably say "patterns are the same as for glob.glob()"

@jugmac00
Copy link
Contributor Author

Thanks!

I will update my current PR, and I will also fix the documentation for Path.glob.

@jugmac00
Copy link
Contributor Author

On a second thought, and after reading the documentation for glob.glob(), I am not sure whether linking to it directly would be very helpful.

  • unlike the fnmatch documentation there is no syntax overview
  • unlike the fnmatch documentation there are no explanations (there are some above that paragraph)
  • glob.glob() has options to change its scope, ie include subdirectories and hidden directories; Path.glob does not have any options; just linking to glob.glob() would leave the reader in the dark whether Path.glob include these or not
  • the introductory paragraph mentions (emphasis on unlike)

Note that files beginning with a dot (.) can only be matched by patterns that also start with a dot, unlike fnmatch.fnmatch() or pathlib.Path.glob()

I think linking to glob.glob() would cause more confusion - at least as it is now.

@barneygale What do you think of adding a pattern syntax table (similar to the one for fnmatch) to Path.glob and then link from Path.rglob to Path.glob? Or would that overstate the case? Or maybe I miss something.

@barneygale
Copy link
Contributor

barneygale commented Jan 18, 2023

@barneygale What do you think of adding a pattern syntax table (similar to the one for fnmatch) to Path.glob and then link from Path.rglob to Path.glob? Or would that overstate the case? Or maybe I miss something.

I think that's an excellent idea. Perhaps something like:

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

@barneygale
Copy link
Contributor

The docs for PurePath.match() should also link to the table, but should note that ** is unsupported and works just like *.

ambv pushed a commit that referenced this issue Jan 20, 2023
The documentation for `rglob` did not mention what `pattern` actually
is.

Mentioning and linking to `fnmatch` makes this explicit, as the
documentation for `fnmatch` both shows the syntax and some explanation.
jugmac00 added a commit to jugmac00/cpython that referenced this issue Jan 21, 2023
Unlike previously stated, the patterns used for `Path.glob`, `Path.rglob`
and `Path.match` does not behave like the ones for `fnmatch`.

Remove the refernce to `fnmatch` and provide an overview of the
available patterns.
jugmac00 added a commit to jugmac00/cpython that referenced this issue Jan 21, 2023
Unlike previously stated, the patterns used for `Path.glob`, `Path.rglob`
and `Path.match` do not behave like the ones for `fnmatch`.

Remove the refernce to `fnmatch` and provide an overview of the
available patterns.
jugmac00 added a commit to jugmac00/cpython that referenced this issue Jan 21, 2023
Unlike previously stated, the patterns used for `Path.glob`, `Path.rglob`
and `Path.match` do not behave like the ones for `fnmatch`.

Remove the refernce to `fnmatch` and provide an overview of the
available patterns.
jugmac00 added a commit to jugmac00/cpython that referenced this issue Jan 21, 2023
Unlike previously stated, the patterns used for `Path.glob`, `Path.rglob`
and `Path.match` do not behave like the ones for `fnmatch`.

Remove the refernce to `fnmatch` and provide an overview of the
available patterns.

Co-authored-by: Barney Gale <[email protected]>
jugmac00 added a commit to jugmac00/cpython that referenced this issue Jan 21, 2023
Provide an overview of available patterns for `Path.glob` and reference
it from `Path.rglob` and `Path.match`.

Co-authored-by: Barney Gale <[email protected]>
barneygale added a commit to barneygale/cpython that referenced this issue Jan 13, 2024
Explain the `match()` / `glob()` / `rglob()` pattern language in its own
section. Move `rglob()` documentation under `glob()` and reduce duplicated
text.
barneygale added a commit to barneygale/cpython that referenced this issue Jan 26, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Jan 30, 2024
barneygale added a commit that referenced this issue Feb 26, 2024
Explain the `full_match()` / `glob()` / `rglob()` pattern language in its own section. Move `rglob()` documentation under `glob()` and reduce duplicated text.
@barneygale
Copy link
Contributor

Sorted in the 3.13 docs. Can backport if folks are interested, but it'll need to be a little different due to the introduction of full_match() in 3.13, and the fix for patterns ending **. Thanks for reporting @jugmac00.

woodruffw pushed a commit to woodruffw-forks/cpython that referenced this issue Mar 4, 2024
…on#114030)

Explain the `full_match()` / `glob()` / `rglob()` pattern language in its own section. Move `rglob()` documentation under `glob()` and reduce duplicated text.
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 25, 2024
…on#114030)

Explain the `full_match()` / `glob()` / `rglob()` pattern language in its own section. Move `rglob()` documentation under `glob()` and reduce duplicated text.
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
…on#114030)

Explain the `full_match()` / `glob()` / `rglob()` pattern language in its own section. Move `rglob()` documentation under `glob()` and reduce duplicated text.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir topic-pathlib
Projects
None yet
Development

No branches or pull requests

3 participants