GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-101112: Add "pattern language" section to pathlib docs by barneygale · Pull Request #114030 · python/cpython

Conversation

@barneygale

@barneygale barneygale commented Jan 13, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Explain the full_match() / glob() / rglob() pattern language in its own section. Move rglob() documentation under glob() and reduce duplicated text.

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

📚 Documentation preview 📚: https://cpython-previews--114030.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@barneygale
pythonGH-101112: Add "pattern language" section to pathlib docs
db927ea
Explain the `match()` / `glob()` / `rglob()` pattern language in its own
section. Move `rglob()` documentation under `glob()` and reduce duplicated
text.
@barneygale barneygale added docs Documentation in the Doc dir topic-pathlib labels Jan 13, 2024
@bedevere-app bedevere-app Bot added the awaiting core review label Jan 13, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Jan 13, 2024
Path.rglob -> documentation does not specify what pattern is #101112
Closed
@barneygale barneygale added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Jan 13, 2024
@barneygale
Delete news entry
fbe11f3
@barneygale barneygale added the skip news label Jan 16, 2024
barneygale added 5 commits January 26, 2024 01:24
@barneygale
Simplify presentation.
aa94135
@barneygale
Merge branch 'main' into pythongh-101112
3a0b6ce
@barneygale
Convert to table, add examples.
9fe2866
@barneygale
Fix broken table.
42a75b8
@barneygale
Final tweaks
44face0
@barneygale
barneygale requested review from AA-Turner and zooba January 26, 2024 02:14
zooba
zooba reviewed Jan 26, 2024
View reviewed changes
Comment thread Doc/library/pathlib.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@barneygale
Reword note on **, move paragraph on escaping wildcards up.
23d4a3f
@barneygale

barneygale commented Jan 27, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

How patterns with trailing slashes should work:

  1. In glob(), only directories are matched
  2. In glob(), results also have trailing slashes
  3. In full_match(), the path must have the same trailing slash configuration.

However pathlib's implementation of globbing only supports (1), and it's more-or-less impossible to support (2) and (3) in a backwards-compatible way. Because of this, I've not documented trailing slashes in this PR. Too many caveats. They get a mention in the glob() documentation instead.

See also: #106747

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@barneygale barneygale removed needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Jan 27, 2024
@zooba

zooba commented Jan 29, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Maybe it's worth mentioning that trailing slashes are currently inconsistent and to check individual docs, but also recommend a way to use them consistently so that as we make fixes, you're less likely to be affected?

e.g. if we'd been telling people "yeah, glob("**") will only include directories right now, but if you do glob("**/") then we'll know you meant it and won't ever change it on you" it would be less trouble to make that fix.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@barneygale

barneygale commented Jan 30, 2024

Copy link
Copy Markdown
Contributor Author

Honestly I think it's a dead end given the strength of feeling in this thread: https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389

The only possible avenue I see is that we introduce a new class like RawPath that doesn't perform normalization. But that would also face considerable opposition: https://discuss.python.org/t/suggestion-for-pathlib-differentiate-explicit-and-implicit-local-paths-pathlib-strictpath/31235. And even if it came to pass, it wouldn't affect pathlib.Path so preparation isn't possible for users I don't think.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba

zooba commented Jan 30, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

By the logic I see there, ** should return both files and directories with no way to prevent it - that is, **/ should also return files and directories. So clearly we need to pick some logic that has exceptions, because those seem pretty bad.

Since we're talking about a pattern here, rather than a path, I think it's okay for **/ to restrict to directories, **/* to restrict to files, and ** to include both. None of the resulting Path objects will have trailing slashes, but there's a way to efficiently filter, and that's enough. Right now, there isn't even a good way to filter by collecting everything and using a comprehension (expensive, but obvious).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@barneygale

barneygale commented Jan 30, 2024

Copy link
Copy Markdown
Contributor Author

I agree that making trailing slashes meaningful to patterns in glob() but nowhere else is weird and messy. I think Antoine pointed that out in the thread too. With what I know now, I might not have accepted #10349 so readily, and instead suggested we add optional files=True, dirs=True arguments.

... but at least it only affects glob(), whereas to generally support paths with trailing slashes (required to implement behaviours (2) and (3) from my earlier post) would require much more disruptive changes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@barneygale
Explain trailing slash handling.
406cf4d
@barneygale

barneygale commented Jan 30, 2024

Copy link
Copy Markdown
Contributor Author

I've added a couple of paragraphs that attempts to explain how trailing slashes work, lmk what you think?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

barneygale
barneygale commented Jan 30, 2024
View reviewed changes
Comment thread Doc/library/pathlib.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

barneygale added 2 commits January 30, 2024 19:54
@barneygale
Merge branch 'main' into pythongh-101112
d33037d
@barneygale
Move language change notices into new section.
b60970b
@barneygale barneygale mentioned this pull request Jan 30, 2024
Glob behavior is inconsistent across libraries #106747
Closed
zooba
zooba reviewed Jan 30, 2024
View reviewed changes
Comment thread Doc/library/pathlib.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

barneygale added 2 commits January 30, 2024 23:08
@barneygale
Soften note about trailing slashes.
7caf247
@barneygale
Use definition list for wildcards, similar to re docs.
5311f45
@barneygale

barneygale commented Feb 10, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Is it worth adding a "Comparison to glob module" section? It would note that:

  1. Hidden files are not special (equivalent to glob(include_hidden=True))
  2. ** is always recursive (equivalent to glob(recursive=True))
  3. ** doesn't follow symlinks by default
  4. Trailing slashes are not preserved
  5. bytes paths and fd-based functionality isn't available

It could also note that pathlib's implementation is heckin' fast

zooba reacted with thumbs up emoji zooba reacted with rocket emoji
All reactions
  • 👍 1 reaction
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

barneygale added 2 commits February 12, 2024 23:35
@barneygale
Add "comparison to the glob module" section
1461d8b
@barneygale
Remove duplicated text
fb20b5c
@barneygale
barneygale requested a review from zooba February 13, 2024 00:13
zooba
zooba approved these changes Feb 13, 2024
View reviewed changes

@zooba zooba left a comment

Copy link
Copy Markdown
Member

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.

Few minor suggestions, but looks good.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/pathlib.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/pathlib.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/pathlib.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/pathlib.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/pathlib.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Feb 13, 2024
barneygale added 3 commits February 25, 2024 23:55
@barneygale
Address review feedback
d7e6ed1
@barneygale
Clarifications
ec80126
@barneygale
Missed edit.
5cc4894
@barneygale

barneygale commented Feb 26, 2024

Copy link
Copy Markdown
Contributor Author

Thanks for the review, Steve.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@barneygale
barneygale enabled auto-merge (squash) February 26, 2024 00:16
@barneygale
barneygale merged commit e921f09 into python:main Feb 26, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Feb 26, 2024
@barneygale barneygale mentioned this pull request Feb 26, 2024
GH-101112: Provide pattern overview for Path.glob #101223
Closed
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this pull request Mar 4, 2024
@barneygale @woodruffw
pythonGH-101112: Add "pattern language" section to pathlib docs (pyth…
c56c5fb
…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 pull request Mar 25, 2024
@barneygale @adorilson
pythonGH-101112: Add "pattern language" section to pathlib docs (pyth…
a33a073
…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 pull request Apr 17, 2024
@barneygale @diegorusso
pythonGH-101112: Add "pattern language" section to pathlib docs (pyth…
673a3f5
…on#114030)

Explain the `full_match()` / `glob()` / `rglob()` pattern language in its own section. Move `rglob()` documentation under `glob()` and reduce duplicated text.
LukasWoodtli pushed a commit to LukasWoodtli/cpython that referenced this pull request Jan 22, 2025
@barneygale @LukasWoodtli
pythonGH-101112: Add "pattern language" section to pathlib docs (pyth…
dee5761
…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

Reviewers

@zooba zooba zooba approved these changes
@AA-Turner AA-Turner Awaiting requested review from AA-Turner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

docs Documentation in the Doc dir skip news topic-pathlib

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@barneygale @zooba
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.