_sre: fix Match.expand to use _compile_template (#8229)#8256
Conversation
Match.expand delegated to re._expand, which CPython removed in 3.12 during the template-expansion refactor. With the 3.14 stdlib that helper no longer exists, so expand raised AttributeError. Route expand through the compiled-template path (Template::compile -> re._compile_template) and share the template-filling logic with Pattern.sub via a Match::expand_template helper. Each caller still compiles the template once, so sub keeps its no-recompile-per-match fast path. Remove the expectedFailure marker on test_re.test_expand. Assisted-by: Claude Code:claude-opus-4-8
📝 WalkthroughWalkthroughTemplate expansion is centralized in ChangesTemplate expansion
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/re dependencies:
dependent tests: (81 tests)
Legend:
|
ShaharNaveh
left a comment
There was a problem hiding this comment.
lgtm, tysm:)
welcome to the project<3
Summary
Match.expand delegated to re._expand, which CPython removed in 3.12 during the template-expansion refactor. With the 3.14 stdlib that helper no longer exists, so expand raised AttributeError.
Route expand through the compiled-template path
(Template::compile -> re._compile_template) and share the template-filling logic with Pattern.sub via a Match::expand_template helper. Each caller still compiles the template once, so sub keeps its no-recompile-per-match fast path.
Remove the expectedFailure marker on test_re.test_expand.
Assisted-by: Claude Code:claude-opus-4-8
Summary by CodeRabbit