Repository navigation
Conversation
Member
|
Sorry but I'm closing, the issue author asked to open the PR, please read the issue before opening. |
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.
Fixes #159717.
Thanks to @digit50 for the original report and reproducer.
glob.translate()currently discards the star positions returned byfnmatch._translate(). As a result, short patterns such as'*a' * 8 + '*b'repeatedly backtrack inPurePath.match(),PurePath.full_match()andPath.glob().Reuse the atomic-star joining logic for each ordinary glob segment, with a separator-excluding star. Keep the existing fast path for segments with fewer than two stars, and leave recursive
**and hidden-name handling inglob.fnmatch.translate()retains its existing public regex output.A fixed part that can consume a separator must remain backtrackable: for example,
*[!x]*xcurrently matchesa/x. The separator check also covers case-sensitive and case-insensitive uses with custom separators. This patch preserves that behavior instead of changing character-class semantics as a side effect.Validation on Windows x64, a Debug build of main at
4c73f50ca9885e5850dae64463e87cf5e80992a1:test_fnmatch,test_glob,test_pathlib,test_shutil,test_tarfile,test_zipfile,test_unittest: all seven modules passed; regrtest reportedrun=4,202 skipped=740.run=1,471 skipped=533). Skips include platform/feature-dependent tests; this is not a Linux validation run.Tools/patchcheck/patchcheck.pyandgit diff --checkpass; a NEWS entry is included.For the issue's pattern against 36
acharacters, the same Debug interpreter measuredfull_matchat about 631 ms before and 0.096 ms after, and a single-filePath.globat about 1706 ms before and 0.342 ms after. These are warmed-up medians of three calls for this reproducer, not a general performance claim.This does not promise to remove all backtracking involving recursive patterns or character classes that consume separators. Cold translation of multi-star patterns has some additional cost; the change targets excessive matching cost and retains the common zero/one-star translation path.
Prepared with OpenAI Codex assistance for implementation, test generation and review. Builds, tests and measurements were executed locally.