Skip to content

fix: handle Python 3.15 removal of the legacy sre_parse module - #107

Merged
Qubitium merged 1 commit into
mainfrom
fix/py315-sre-parse-removal
Aug 24, 2026
Merged

fix: handle Python 3.15 removal of the legacy sre_parse module#107
Qubitium merged 1 commit into
mainfrom
fix/py315-sre-parse-removal

Conversation

@Qubitium

Copy link
Copy Markdown
Contributor

Problem

Python 3.15 removes the deprecated top-level sre_parse / sre_compile / sre_constants modules (previously slated for removal, now gone in 3.15.0rc1). pypcre's parser loader in pcre/_stdlib_re.py imported sre_parse unconditionally whenever re._parser was absent, so on 3.15 that path failed with an opaque ModuleNotFoundError: 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_fallback failed; everything else passed.

Fix

  • pcre/_stdlib_re.py: guard the legacy fallback import with try/except ModuleNotFoundError and raise a clear ImportError naming both supported internals (re._parser on Python 3.11+, sre_parse on Python <= 3.10) when neither exists.
  • tests/test_python_coverage_audit.py::test_stdlib_parser_fallback: version-aware expectations — return/validate a parser where sre_parse still exists (<= 3.14), expect ImportError where it has been removed (3.15+).

Forward-compatibility verification on 3.15.0rc1

  • Full suite: 832 passed / 19 skipped; only failure is test_cache_strategy_benchmark, which fails on pristine main as well (timing-sensitive).
  • New-in-3.15 re.prefixmatch() / re.Pattern.prefixmatch(): signatures fingerprint-match pypcre's existing aliases and span behavior matches re (including positional pos).
  • All module-level signature parity tests pass against the 3.15 stdlib.
  • import pcre and hot paths run clean under -W error::DeprecationWarning on 3.15.

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.
@Qubitium
Qubitium merged commit 50e0c9e into main Aug 24, 2026
19 checks passed
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