Skip to content

Preserve custom regex matching when selecting native backends - #184

Open
anticipate218 wants to merge 1 commit into
cpburnz:masterfrom
anticipate218:fix/native-backend-custom-matching
Open

anticipate218 wants to merge 1 commit into
cpburnz:masterfrom
anticipate218:fix/native-backend-custom-matching

Conversation

@anticipate218

Copy link
Copy Markdown

A RegexPattern subclass can override match_file() to apply additional filtering, but native backend selection only checks its stored regex. With RE2 or Hyperscan installed, the default backend silently bypasses that method. For example, a pattern that selects Python files only outside private/ matches private/secret.py after installing a native engine, although the simple backend correctly excludes it.

Require native-compatible patterns to use the original RegexPattern.match_file bound to the same object. Automatic selection then preserves overridden, inherited, instance-assigned, or delegated matching through the simple backend. Explicit native selection reports the existing compatibility error. Inactive patterns and subclasses inheriting the original method retain native execution.

Seven regression methods cover both spec classes, both real native engines, include/exclude combinations, +/+=, pattern indices, inactive controls and ordinary subclasses. This is separate from #183, which optimizes the simple backend and does not change native compatibility selection.

Validation on Windows / CPython 3.13.5, with google-re2 1.1.20251105 and hyperscan 0.9.1 installed:

  • Original base: 30 failing subtests and 12 passing controls across the seven methods. Fixed: all 42 subtests pass.
  • Complete python -m unittest discover -t . -s tests/: 329 tests pass with no skips.
  • Independent verification: 268 combinations pass, including class/static/instance overrides and delegation to another pattern.
  • Strict Sphinx 9.2 HTML build, sdist/wheel build, Twine metadata checks and git diff --check pass. The final test-only type annotation was added after the distribution build; production files are unchanged.
  • Mypy and Pyright retain 8 and 6 existing diagnostics respectively, reproduced on the unmodified base. No new diagnostics remain in the changed files; repository-wide typing is not claimed clean.

Other Python versions, Linux/macOS and separately created tox backend environments were not run. The documentation build used Sphinx 9.2.0 rather than the pinned 9.1.0 because the pinned dependency installation timed out. No production incident or prevalence is claimed. README and changelog documentation are updated; unrelated existing generated-document drift is left unchanged.

AI assistance: OpenAI Codex investigated the implementation, prepared the patch/tests and draft, and ran validation with independent automated review. No human code review is claimed.

Keep custom RegexPattern matching on the simple backend during automatic selection. Reject it through existing explicit native compatibility checks, including instance delegation, while preserving native execution for standard and inactive patterns.

Assisted-by: OpenAI Codex

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant