Forward pyexpat lexical events#8264
Conversation
Forward processing instructions, comments, and CDATA boundaries already emitted by xml-rs so registered Python handlers observe CPython-compatible events. Constraint: Reuse existing xml-rs events without changing the dependency Confidence: high Scope-risk: narrow Tested: prek; test_pyexpat; test_sax; 402 extra tests; workspace tests; clippy Assisted-by: Codex:gpt-5.6-sol
📝 WalkthroughWalkthroughThe expat-compatible parser preserves CDATA and comment events, dispatches processing instruction, comment, and CDATA handlers, and adds a test verifying the ordered callbacks for mixed XML content. ChangesExpat event compatibility
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant XMLDocument
participant PyExpatLikeXmlParser
participant xml-rs
participant ExpatHandlers
XMLDocument->>PyExpatLikeXmlParser: Parse mixed XML content
PyExpatLikeXmlParser->>xml-rs: Preserve CDATA and comments
xml-rs->>PyExpatLikeXmlParser: Emit XML events
PyExpatLikeXmlParser->>ExpatHandlers: Invoke matching callbacks
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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/xml dependencies:
dependent tests: (34 tests)
Legend:
|
| let str = PyStr::from(chars).into_ref(&vm.ctx); | ||
| invoke_handler(vm, &self.character_data, (str,)); | ||
| } | ||
| Ok(XmlEvent::ProcessingInstruction { name, data }) => { |
There was a problem hiding this comment.
I can't comment on things outside the diff. can you please make the match to be:
- match e {
+ match e? {then we could do:
- Ok(XmlEvent::Foo { .. })
+ XmlEvent::Foo { ..}
ShaharNaveh
left a comment
There was a problem hiding this comment.
tysm!
can you please unmark the passing tests?
Summary
Forward processing instructions, comments, and CDATA boundaries from
xml-rsto the correspondingpyexpathandlers.Problem
RustPython exposed
ProcessingInstructionHandler,CommentHandler, and the CDATA handlers, but the parser discarded those events. Code using the handlers received only character data.Fix
Preserve comment and CDATA events in the parser configuration, then dispatch them through the existing handler bridge. Processing instructions without data are passed as an empty string, matching CPython.
Testing
cargo run -- extra_tests/snippets/stdlib_xml.pycargo run --release -- -m test test_pyexpatcargo run --release -- -m test test_saxprek run --all-filesextra_tests: 402 passedSummary by CodeRabbit
Bug Fixes
Tests