Preserve externally compiled regex flags during backend selection - #151
Open
Master-Norna wants to merge 1 commit into
Open
Master-Norna wants to merge 1 commit into
Master-Norna wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Both native backends rebuild
RegexPattern.regex.patternwithout its compile-time flags. As a result, installing an optional backend can silently change matching results for precompiled Python regexes.This patch falls back to
simpleforNone/bestwhen an active standard-libraryre.Patternhas flags that cannot be reconstructed from its expression. Explicitre2/hyperscanselection raisesValueErrorwith guidance to usebackend='simple'. Comparing against the expression's own flags preserves existing inline-flag behavior; ordinary gitignore patterns keep their current native backend. This does not attempt to make all Python and native regex syntax or Unicode semantics equivalent.It also makes
+=leave the spec unchanged if rebuilding the backend is rejected.Regression tests cover I/M/S/X/A and combinations, Unicode case folding, verbose comments with invalid bare regex syntax, warning-as-error handling without leaking probe warnings, mixed inclusion/exclusion and indices, inline flags, no-op rules, GitIgnoreSpec directory precedence, and rejected in-place additions.
Validation on Windows / CPython 3.12.14:
tox -e ci-base,ci-re2,ci-hyperscan: all three isolated environments passed.-W error::FutureWarning, strict Sphinx build, and sdist/wheel build: passed._typing.pyerrors on the unmodified base and the patch, with no additional diagnostics.