GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||
GeezerVison is showing github.com — GH-72904: Add `glob.translate()` function by barneygale · Pull Request #106703 · python/cpython Conversation
|
|
~20% globbing speedup: $ ./python -m timeit -s 'from pathlib import Path; p = Path()' 'list(p.glob("**/*", follow_symlinks=False))' 2 loops, best of 5: 175 msec per loop # before 2 loops, best of 5: 146 msec per loop # after |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
fnmatch.translate()fnmatch.translate()
There was an error while loading. Please reload this page.
Co-authored-by: Jason R. Coombs <[email protected]>
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
fnmatch.translate()glob.translate() function
|
I've moved this to a new It was easy enough to implement a recursive argument, so I did that and made its default It's much harder to implement an include_hidden argument, so I've left that for now. I don't feel great about it, tbh. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Right, after some futzing around I'm going to mark this PR as ready again. In (In #109879 I've re-implemented In In |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Timings: So |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
A desk review:
A
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Adam Turner <[email protected]>
|
I've realised that the docs are a bit skew-whiff. Fix is in a separate PR: #110418 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Is it correct to keep duplicated path separators? >>> glob.translate('a//b') '(?s:a//b)\\Z' |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
>>> os.makedirs('a/b') >>> glob.glob('a//b') ['a//b'] So I reckon yes? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Also, the number of additional slashes is meaningful in some cases, e.g. in Windows UNC paths or POSIX paths starting with two forward slashes. I don't think a pattern like |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Hey @encukou, do you think I can merge this, or should I wait for a more complete review from someone? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Oh, I should have been more clear that I wouldn't get to a thorough review in any reasonable time. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Add `glob.translate()` function that converts a pathname with shell wildcards to a regular expression. The regular expression is used by pathlib to implement `match()` and `glob()`. This function differs from `fnmatch.translate()` in that wildcards do not match path separators by default, and that a `*` pattern segment matches precisely one path segment. When *recursive* is set to true, `**` pattern segments match any number of path segments, and `**` cannot appear outside its own segment. In pathlib, this change speeds up directory walking (because `_make_child_relpath()` does less work), makes path objects smaller (they don't need a `_lines` slot), and removes the need for some gnarly code. Co-authored-by: Jason R. Coombs <[email protected]> Co-authored-by: Adam Turner <[email protected]>
Add `glob.translate()` function that converts a pathname with shell wildcards to a regular expression. The regular expression is used by pathlib to implement `match()` and `glob()`. This function differs from `fnmatch.translate()` in that wildcards do not match path separators by default, and that a `*` pattern segment matches precisely one path segment. When *recursive* is set to true, `**` pattern segments match any number of path segments, and `**` cannot appear outside its own segment. In pathlib, this change speeds up directory walking (because `_make_child_relpath()` does less work), makes path objects smaller (they don't need a `_lines` slot), and removes the need for some gnarly code. Co-authored-by: Jason R. Coombs <[email protected]> Co-authored-by: Adam Turner <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.