Support Python single-byte codecs in pyexpat by youknowone · Pull Request #9938 · RustPython/RustPython
Repository navigation
Support Python single-byte codecs in pyexpat - #9938
Merged
youknowone merged 2 commits into main from dot/xml-single-byte-codecs-3152 Nov 26, 2026
Merged
Support Python single-byte codecs in pyexpat #9938 youknowone merged 2 commits into main from dot/xml-single-byte-codecs-3152
Conversation
youknowone commented Nov 18, 2026 · edited Loading
Copy link Copy Markdown
Member
Summary
Support Python single-byte text codecs in pyexpat, including the ISO-8859, Windows code-page, KOI8 and Mac codec families exercised by CPython 3.15.2.
- Build and validate Expat-style 256-entry maps through Python's codec registry, then decode lazily on the XML reader rather than rewriting complete documents.
- Preserve declared versus explicit encoding lookup order, XML-declaration callbacks, BOM/preamble handling, terminal codec failures and original-byte position accounting. Share the bridge between threaded and synchronous readers without calling Python from the parser thread.
- Remove nine stale expected-failure markers, enabling ten test occurrences across pyexpat, both ElementTree implementations and XML-RPC. Add one focused custom-codec/streaming regression to the existing XML snippet.
This is independent of #9662 's DTD/entity work and does not implement missing namespace, DTD, external-entity or amplification-accounting features.
Validation
- Relevant canonical modules:
test_pyexpat test_xml_etree test_xml_etree_c test_sax test_minidom test_plistlib: 979 tests, 36 skips, success (remaining unrelated expected failures retained). - Existing
stdlib_xml.pysnippet passes on RustPython and CPython 3.15.2. cargo test -p rustpython-stdlib --lib: 64 passed, 0 failed or ignored.- 43 custom-codec differential cases exercised with the threaded reader and post-fork synchronous fallback. Exception classes match CPython; callback/codec ordering matches except the pre-existing xml-rs buffered-text loss immediately before invalid input.
- Workspace Rust/doc tests excluding wasm, venvlauncher and C-API: 1,619 passed, 21 ignored. Workspace Clippy succeeded; final scoped Clippy succeeded after resolving local style warnings (existing wasi-host manifest / VM warnings remain).
- Final exact-commit binary reran all six canonical modules, the XML snippet and both differential-reader paths successfully.
- Eight alternating development-build smoke benchmark pairs for ordinary UTF-8 parsing: baseline median 0.16883s, candidate 0.16613s. This is a non-regression smoke check, not a release-profile speedup claim.
Exact CPython diagnostic parity is not claimed: existing event positions and mixed UTF-16-header/single-byte-body column behavior still differ. No synthetic markup or test weakening hides those limitations. Windows/macOS/WASI execution and C-API tests have not been performed locally; C-API work is deferred.
AI disclosure: implementation, review and validation were assisted by OpenAI Codex; the exact model identifier is unavailable in this session. Maintainer review remains pending.
CI follow-up
The first head exposed three additional XML-RPC encoding XPASS cases on Linux, macOS and Windows. Their obsolete expected-failure markers are removed in 25cc0ba; all 94 XML-RPC tests pass locally with walltime resources enabled. The updated XML snippet passes both RustPython and CPython 3.15.2 through the pytest harness (2 passed). The review-bot suggestion to return None explicitly for unrecognized codec names is addressed.
The first Windows run also failed the unrelated asyncio SSL shutdown/backpressure test with "the transport never paused writing", including its retry. This is not claimed fixed by the XML change; a separate investigation is underway. Checks after failed Python suites were skipped. Rust tests, Clippy, Miri and WASI checks passed on the first head. CodSpeed's benchmark build/execution and pyperformance were skipped, so there is no hosted performance measurement. CI for the updated head is pending.
Support Python single-byte codecs in pyexpat
7db364e
Resolve validated Expat-style codec maps lazily across threaded and synchronous readers, preserve encoding callbacks and raw byte offsets, and enable the related canonical XML tests. Assisted-by: Codex:unspecified
coderabbitai
Bot
commented
Nov 18, 2026
·
edited
Loading
Copy link Copy Markdown
Contributor
|
Caution Review failedThe pull request is closed.
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. Share |
github-actions
Bot
commented
Nov 18, 2026
·
edited
Loading
Copy link Copy Markdown
Contributor
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/xml dependencies:
dependent tests: (39 tests)
[x] lib: cpython/Lib/xmlrpc dependencies:
dependent tests: (4 tests)
Legend:
|
Bot
found potential problems Nov 18, 2026
View reviewed changes
Enable XML-RPC encoding cases fixed by the codec bridge
25cc0ba
Remove three now-passing expected-failure markers and make the custom codec search callback return None explicitly for unrelated names. Assisted-by: Codex:unspecifiedyouknowone marked this pull request as ready for review November 26, 2026 13:46 youknowone merged commit
0a828d8
into
main
Nov 26, 2026
31 of 32 checks passed
youknowone
deleted the
dot/xml-single-byte-codecs-3152
branch
November 26, 2026 13:47
chatgpt-codex-connector
Bot
commented
Nov 26, 2026
·
edited
Loading
Copy link Copy Markdown
|
Codex Review Summary : ✅ Completed
This comment shows the latest Codex review activity on this pull request.
Your team has set up Codex to review pull requests in this repo . Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Bot
reviewed Nov 26, 2026
View reviewed changes
chatgpt-codex-connector
Bot
left a comment
Copy link Copy Markdown
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25cc0ba0f0
Your team has set up Codex to review pull requests in this repo . Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Comment thread crates/stdlib/src/pyexpat.rs Comment on lines +2555 to +2558| if !unicode_input | ||
| && self.encoding.is_none() | ||
| && !self.declaration.read().complete | ||
| && !isfinal |