GeezerVison is showing github.com — Parse Unicode XML input as UTF-8 by youknowdot · Pull Request #9785 · RustPython/RustPython
Conversation
youknowdot
commented
Nov 10, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
- Configure the existing XML backend as UTF-8 when the initial
Parse input is str, ignoring its encoding declaration. Previously UTF-8 bytes from Python strings were decoded according to that declaration, corrupting text such as £€.
- Match CPython 3.15's
XML_SetEncoding("utf-8") for Unicode input. Like Expat, once parsing starts, later string input cannot change the encoding. Empty initial byte/string chunks and mixed inputs are regression-tested.
- Enable two SAX tests and one ElementTree test. No new persistent state, decoder, or intermediate transcoding is added.
Directly based on main, independent of #9662's DTD handling and #9784's error-position aliases. This does not fix the separate unsupported byte encodings or ParserCreate(encoding=...) implementation.
Validation
-
Release -m test test_sax test_xml_etree: 418 tests, success; 37 existing expected failures and one skip remain.
-
CPython 3.15.1: the three restored tests pass.
-
CPython/RustPython pytest -v test_snippets.py -k stdlib_pyexpat: both pass, including mixed-input regressions.
-
Workspace Rust tests and separate CAPI tests.
-
Strict workspace/all-target and separate CAPI Clippy (-D warnings).
-
Repository pre-commit hooks.
-
This PR follows the AI policy. Assisted by OpenAI Codex (model version not exposed by this runtime); disclosed in the commit trailer.
Summary by CodeRabbit
- Bug Fixes
- Improved XML parsing for text input with encoding declarations, including declarations that specify unsupported encodings.
- Corrected incremental parsing when text and byte input are mixed across chunks, so parsed character data is handled consistently.
- XML file parsing continues to use the encoding information provided by the file rather than treating file contents as Unicode text.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
chatgpt-codex-connector[bot] reacted with thumbs up emoji
coderabbitai
Bot
commented
Nov 10, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

Walkthrough
-
The parser passes input type from Parse to backend configuration. Unicode input selects UTF-8 and ignores invalid encoding declarations. Byte-like input and ParseFile use the default encoding configuration. Tests cover encoding declarations and incremental input chunks.
Changes: pyexpat Input Encoding
| Layer / File(s) |
Summary |
Configure encoding from input type crates/stdlib/src/pyexpat.rs, extra_tests/snippets/stdlib_pyexpat.py |
Parse passes whether its input is a string through the feed path to backend configuration. Unicode input selects UTF-8 and ignores invalid encoding declarations. Byte-like input and ParseFile use the default encoding configuration. Tests cover encoding declarations and mixed input chunks. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related issues
Possibly related PRs
Suggested reviewers: youknowone
Merge Risk: Minimal · up to bd543
-
No actionable issue remains from this review; the change is ready for normal merge checks.
Pre-merge checks: 4 · 1
-
Failed checks: 1 warning
| Check name |
Status |
Explanation |
Resolution |
| Docstring Coverage |
 |
Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… |
Write docstrings for the functions missing them to satisfy the coverage threshold. |
Passed checks: 4 passed
-
| Check name |
Status |
Explanation |
| Description Check |
 |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
 |
The title clearly summarizes the main change: parsing Unicode XML input as UTF-8. |
| Linked Issues check |
 |
Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check |
 |
Check skipped because no linked issues were found for this pull request. |
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 2 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
-
Generate unit tests (beta)
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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
-
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
📦 Library Dependencies
The following Lib/ modules were modified. Here are their dependencies:
[x] lib: cpython/Lib/xml
[x] test: cpython/Lib/test/test_xml_etree.py (TODO: 16)
[ ] test: cpython/Lib/test/test_xml_etree_c.py
[x] test: cpython/Lib/test/test_minidom.py (TODO: 1)
[x] test: cpython/Lib/test/test_pulldom.py
[ ] test: cpython/Lib/test/test_pyexpat.py (TODO: 38)
[x] test: cpython/Lib/test/test_sax.py (TODO: 20)
[x] test: cpython/Lib/test/test_xml_dom_minicompat.py
[x] test: cpython/Lib/test/test_xml_dom_xmlbuilder.py
dependencies:
dependent tests: (39 tests)
- xml: test_doctest test_minidom test_pulldom test_pydoc test_pyexpat test_regrtest test_sax test_typing test_xml test_xml_dom_minicompat test_xml_dom_xmlbuilder test_xml_etree
- plistlib: test_plistlib
- platform: test__locale test__osx_support test_android test_asyncio test_baseexception test_builtin test_calendar test_cmath test_ctypes test_fcntl test_math test_mimetypes test_os test_platform test_shutil test_socket test_ssl test_startfile test_strptime test_sysconfig test_time test_tkinter test_winreg test_wsgiref
- webbrowser: test_webbrowser
- xmlrpc.client: test_xmlrpc
Legend:
[+] path exists in CPython
[x] up-to-date, [ ] outdated
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Merging this PR will not alter performance
✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1
Comparing youknowdot:fix/expat-unicode-input (05fe1e1) with main (9afd18b)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
| Review |
Status |
Commit |
Review trigger |
| 📝 Code Review |
✅ Completed 2026-11-10T15:06:14.581919Z |
bd543f9 |
New commits |
ℹ️ About Codex in GitHub
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" or "@codex security review".
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Select UTF-8 for an initial str feed and ignore its encoding declaration, as CPython does with XML_SetEncoding. Preserve the initial encoding for subsequent feeds, including mixed bytes/str input. Enable three SAX and ElementTree regression tests.
Assisted-by: OpenAI Codex:model version not exposed
auto-merge was automatically disabled
November 10, 2026 14:58 Head branch was pushed to by a user without write access
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|