Repository navigation
Fix negated glob character classes - #162
Merged
Merged
Conversation
jaraco
reviewed
Oct 3, 2026
jaraco
left a comment
Owner
There was a problem hiding this comment.
Thanks for the contrib. It would be nice if the problem description provided a little more context. In particular, instead of stating that the behavior is wrong, elaborate on why the behavior is wrong. I think the answer is that glob patterns do support character classes and need to be translated to regular expressions as well. How do we know that?
Owner
|
I wrote these comments, but I'll also be addressing them. |
- Dispatch symmetrically to _replace_set/_replace_plain. - Extract _strip_fnmatch with a docstring, matching the end marker rather than slicing. - Use the parameterize helper for the character-class test cases. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 21, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Path.glob('[!a].txt')currently matchesa.txtand!.txt, because glob character classes are copied directly into the generated regular expression. Shell-style!negation is consequently treated as a literal character. Conversely,[^a]is incorrectly interpreted as regex negation.This is wrong because glob character classes have shell-style semantics, not regex semantics, and so need translation like the other wildcards. The
fnmatchdocs (whichglobandpathlibfollow) define[!seq]as matching any character not in seq, and give^no special meaning (fnmatch.translate('[^a]')produces[\^a]).zipfile.Path.globshould agree withpathlib.Path.glob.Translate recognized character classes using
fnmatch.translate, then remove its outer group/end marker before inserting the result into the complete pattern. A separator guard keeps negated classes from matching across directory boundaries. Other wildcard and character-class tokenization logic is unchanged.The new public
Path.globregression covers negation, caret inclusion, positive/negative ranges, directory matches and a path-separator control, for both implicit and explicit archive directories. Before the source change, 12 of the 16 subcases failed; all now pass.Validation on Windows:
tox -e py312: 106 passed, 2 xfailed, 8 failed. All eight failures are existing Ruff checks and reproduce on unmodified source (106 passed, 1 xfailed, 8 failed); the marked performance tests vary between pass/xfail across runs.tox -e docs(Sphinx with warnings as errors and sphinx-lint): passed.fnmatch.translateend-marker formats.git diff --check: passed.AI assistance: developed with OpenAI Codex and checked through independent Claude Opus and Codex AI reviews. This is not a claim of human review.