fix: align Pattern pos/endpos signatures with re and add sliced-search fallback - #106
Merged
Conversation
…h fallback Pattern.match/search/fullmatch/finditer/findall required keyword-only pos/endpos, breaking drop-in re-style positional calls such as pattern.search(s, 2). Accept them positionally (options stays keyword-only) and, for minimal non-C backends whose search() lacks pos support, fall back to searching a slice with offset tracking so reported spans stay absolute in the original subject.
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.
Problem
re.Patternmethods acceptpos/endpospositionally, but pypcre'sPattern.match/search/fullmatch/finditer/findalldeclared them keyword-only. Drop-inre-style code therefore failed:Fix
posandendpospositionally onPattern.match,search,fullmatch,finditer, andfindall, matching the stdlibre.Patternsignature order; the pypcre-specificoptionsargument remains keyword-only.search()lackspos/endpossupport,Pattern.search()now falls back to searching a slice (subject[pos:endpos]) and returns an internal_OffsetMatchwrapper that shiftsstart()/end()/span()/regsback bypos, so reported spans stay absolute in the original subject while.string,.pos,.endpos, and.restill reference the original subject/pattern.The C backend keeps forwarding
posnatively: slicing alone would change semantics for anchors (^,$),\b, and lookbehinds relative tore, since they would evaluate against the slice boundary rather than the full string.Tests
search/match/fullmatch/finditer/findallresults (spans andpos) against stdlibre, including negative cases.possupport and asserts absolute spans,regs,pos,string, andreon the returned match.Full suite: 832 passed, 19 skipped (
test_cache_strategy_benchmarkfailure is pre-existing onmainand timing-related).