fix: handle Python 3.15 removal of the legacy sre_parse module - #107
Merged
Conversation
Python 3.15 removes the deprecated top-level sre_parse/sre_compile/ sre_constants modules. The _stdlib_re parser loader still imported sre_parse unconditionally whenever re._parser was absent, so any interpreter without re._parser failed with an opaque ModuleNotFoundError instead of a clear error. Guard the fallback import, raise an ImportError that names both supported internals (re._parser on 3.11+, sre_parse on <= 3.10) when neither is available, and make test_stdlib_parser_fallback version-aware: expect a parser where sre_parse still exists and an ImportError where it has been removed.
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
Python 3.15 removes the deprecated top-level
sre_parse/sre_compile/sre_constantsmodules (previously slated for removal, now gone in 3.15.0rc1). pypcre's parser loader inpcre/_stdlib_re.pyimportedsre_parseunconditionally wheneverre._parserwas absent, so on 3.15 that path failed with an opaqueModuleNotFoundError: No module named 'sre_parse'.Found by running the full test suite against Python 3.15.0rc1:
tests/test_python_coverage_audit.py::test_stdlib_parser_fallbackfailed; everything else passed.Fix
pcre/_stdlib_re.py: guard the legacy fallback import withtry/except ModuleNotFoundErrorand raise a clearImportErrornaming both supported internals (re._parseron Python 3.11+,sre_parseon Python <= 3.10) when neither exists.tests/test_python_coverage_audit.py::test_stdlib_parser_fallback: version-aware expectations — return/validate a parser wheresre_parsestill exists (<= 3.14), expectImportErrorwhere it has been removed (3.15+).Forward-compatibility verification on 3.15.0rc1
test_cache_strategy_benchmark, which fails on pristinemainas well (timing-sensitive).re.prefixmatch()/re.Pattern.prefixmatch(): signatures fingerprint-match pypcre's existing aliases and span behavior matchesre(including positionalpos).import pcreand hot paths run clean under-W error::DeprecationWarningon 3.15.