Uh oh!
There was an error while loading. Please reload this page.
GH-73435: Add pathlib.PurePath.full_match() - #114350
Conversation
In 49f90ba we added support for the recursive wildcard `**` in `pathlib.PurePath.match()`. This should allow arbitrary prefix and suffix matching, like `p.match('foo/**')` or `p.match('**/foo')`, but there's a problem: for relative patterns only, `match()` implicitly inserts a `**` token on the left hand side, causing all patterns to match from the right. As a result, it's impossible to match relative patterns from the left: `PurePath('foo/bar').match('bar/**')` is true! This commit reverts the changes to `match()`, and instead adds a new `globmatch()` method that: - Supports the recursive wildcard `**` - Matches the *entire* path when given a relative pattern As a result, `globmatch()`'s pattern language exactly matches that of `glob()`.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
zooba
commented
Jan 22, 2024
Does the problem extend beyond " Presumably |
barneygale
commented
Jan 22, 2024
|
barneygale
commented
Jan 22, 2024
e.g. zsh man page:
|
zooba
commented
Jan 22, 2024
Okay, I definitely like having |
pathlib.PurePath.globmatch()pathlib.PurePath.full_match()Uh oh!
There was an error while loading. Please reload this page.
barneygale
commented
Jan 26, 2024
Thanks for the reviews, both. |
In 49f90ba we added support for the recursive wildcard `**` in `pathlib.PurePath.match()`. This should allow arbitrary prefix and suffix matching, like `p.match('foo/**')` or `p.match('**/foo')`, but there's a problem: for relative patterns only, `match()` implicitly inserts a `**` token on the left hand side, causing all patterns to match from the right. As a result, it's impossible to match relative patterns from the left: `PurePath('foo/bar').match('bar/**')` is true! This commit reverts the changes to `match()`, and instead adds a new `full_match()` method that: - Allows empty patterns - Supports the recursive wildcard `**` - Matches the *entire* path when given a relative pattern
In 49f90ba we added support for the recursive wildcard `**` in `pathlib.PurePath.match()`. This should allow arbitrary prefix and suffix matching, like `p.match('foo/**')` or `p.match('**/foo')`, but there's a problem: for relative patterns only, `match()` implicitly inserts a `**` token on the left hand side, causing all patterns to match from the right. As a result, it's impossible to match relative patterns from the left: `PurePath('foo/bar').match('bar/**')` is true! This commit reverts the changes to `match()`, and instead adds a new `full_match()` method that: - Allows empty patterns - Supports the recursive wildcard `**` - Matches the *entire* path when given a relative pattern
In #101398 we added support for the recursive wildcard
**inpathlib.PurePath.match(). This should allow arbitrary prefix and suffix matching, likep.match('foo/**')orp.match('**/foo'), but there's a problem: for relative patterns only,match()implicitly inserts a**token on the left hand side, causing all patterns to match from the right. As a result, it's impossible to match relative patterns from the left:PurePath('foo/bar').match('bar/**')is true!This PR reverts the changes to
match(), and instead adds a newfull_match()method that:**📚 Documentation preview 📚: https://cpython-previews--114350.org.readthedocs.build/en/114350/library/pathlib.html#pathlib.PurePath.globmatch