Skip to content

Conversation

@fanninpm
Copy link
Contributor

@fanninpm fanninpm commented Jan 27, 2026

This PR is one of a series of PRs in preparation for getting https://rustpython.github.io/pages/regression-tests-results.html to work again by using the Python test suite to generate a JUnit-compatible XML file (and later converting said XML a JSON format the current website can accept).
In pursuit of that, I discovered that xml.parsers.expat.error needs to be available to the interpreter, and I suspect that it's used to let the Python-side XML machinery report a useful error.
Here, I tried to make pyexpat.error available; however, when I submitted this PR, I came up short of my goal, as I currently don't know a useful way of getting pyexpat.error to ailias pyexpat.ExpatError.
In CPython 3.14, the pyexpat module has a pyexpat_state struct that gets initialized with, among other things, a new xml.parsers.expat.ExpatError exception.
When the pyxpat module is initialized, the two objects error and ExpatError are aliased to state->Error.
If anyone knows how to replicate this behavior in RustPython on the Rust side, I would be glad to implement that.

Summary by CodeRabbit

  • New Features
    • Added a new ExpatError exception type for improved error handling in XML parsing operations.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

📝 Walkthrough

Walkthrough

A new PyExpatError exception type is introduced to the _pyexpat module and exported as ExpatError. The change includes expanding imports to include PyException from builtins and reorganizing public symbols in the module prelude.

Changes

Cohort / File(s) Summary
New PyExpatError exception type
crates/stdlib/src/pyexpat.rs
Added public PyExpatError struct deriving Debug, annotated with #[pyexception] and exported as ExpatError. Expanded imports to include PyException from builtins. Reorganized prelude exports to include the new exception type. Includes TODO for module state association.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • youknowone

Poem

🐰 A new exception hops into view,
PyExpatError, shiny and new,
In the _pyexpat burrow it'll stay,
Catching parser woes, come what may! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Add ExpatError and error to pyexpat' accurately describes the main objective: introducing ExpatError exception and making error available in the pyexpat module.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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

Comment @coderabbitai help to get the list of available commands and usage tips.

fanninpm and others added 2 commits January 27, 2026 18:42
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
@github-actions
Copy link
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[ ] lib: cpython/Lib/xml
[ ] test: cpython/Lib/test/test_xml_etree.py (TODO: 56)
[ ] test: cpython/Lib/test/test_xml_etree_c.py
[ ] test: cpython/Lib/test/test_minidom.py
[ ] test: cpython/Lib/test/test_pulldom.py (TODO: 4)
[ ] test: cpython/Lib/test/test_pyexpat.py (TODO: 28)
[ ] test: cpython/Lib/test/test_sax.py

dependencies:

  • xml (native: collections.abc, pyexpat, sys, urllib.parse, xml.dom, xml.dom.NodeFilter, xml.dom.minicompat, xml.dom.minidom, xml.dom.xmlbuilder, xml.etree.ElementTree, xml.parsers, xml.sax, xml.sax._exceptions, xml.sax.handler)
    • codecs (native: builtins, sys)
    • collections (native: _weakref, itertools, sys)
    • copy
    • io (native: _io, _thread, errno, sys)
    • os (native: os.path, sys)
    • weakref (native: _weakref, itertools, sys)
    • contextlib, re, warnings

dependent tests: (7 tests)

  • xml: test_pulldom test_pyexpat test_regrtest test_xml_dom_minicompat test_xml_dom_xmlbuilder
    • plistlib: test_plistlib
    • xmlrpc.client: test_xmlrpc

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@fanninpm fanninpm marked this pull request as ready for review January 28, 2026 00:52
@youknowone youknowone enabled auto-merge (squash) January 28, 2026 01:18
@youknowone youknowone merged commit 4c1c704 into RustPython:main Jan 28, 2026
14 checks passed
@fanninpm fanninpm deleted the xml-parsers-expat-error branch January 28, 2026 01:20
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.

2 participants