Skip to content

Implement CPython 3.15 Expat public error metadata - #9493

Merged
youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:python315-expat-errors-20261030
Oct 31, 2026
Merged

youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:python315-expat-errors-20261030

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implement the public pyexpat error metadata API from CPython 3.15.0:

  • Populate all 44 errors.XML_ERROR_* messages and the codes/messages mappings.
  • Implement ErrorString using index conversion, platform C-long bounds and C-int narrowing, independently of mutable public dictionaries.
  • Initialize and register the qualified pyexpat.errors submodule, preserving the existing error is ExpatError alias.
  • Use actual scripts/update_lib migrate to restore canonical ErrorMessageTest.test_codes, ErrorMessageTest.test_expaterror and ParseErrorTest.test_error_code (also inherited by test_xml_etree_c); all unrelated adaptations and markers remain.

Source reference: CPython 3.15.0 Modules/pyexpat.c at d220409a13b77de7a6c30abe16ea90db01528edc. All 44 table messages also match the bundled Expat XML_ErrorString. This is metadata compatibility, not an assertion that the backend implements every named error condition.

Validation

  • Isolated cargo check, strict Clippy and fresh CLI build passed for the final source. Two earlier Rust typing failures were fixed and retained in local receipts.
  • Two bounded -B -S processes produced 76 identical metadata records per engine against the pinned CPython 3.15.0 reference: all constants/maps, module and exception aliases, valid/invalid scalar codes, index conversion, C-long overflow/C-int narrowing, argument shape and lookup independence from mutable dictionaries.
  • Error observations compare exception classes, not exact diagnostic text. Empty stderr, unchanged bound inputs and process cleanup were verified.
  • No parser was constructed or fed locally. Hosted CI 41112774656 ran the affected modules on macOS, Ubuntu and Windows: the restored metadata test passed, while test_expaterror and both ElementTree error-code variants were unexpected successes on the initial run and rerun. This follow-up retires those two obsolete decorators through the actual updater; the new commit still awaits CI. Local observations are not full canonical/parser coverage.

Scope

No parser construction/feed/state, XML backend or dependency changes. Repeated parsing, encoding resolution, namespace ordering and parser lifecycle behavior are unchanged. The canonical test module constructs a parser in a decorator during import, so its tests are reserved for hosted CI rather than included in metadata-only local observations. No new snippets or Rust tests executing Python behavior.

Summary by CodeRabbit

  • New Features
    • Added Expat error constants, codes, and messages to pyexpat.errors.
    • Added pyexpat.ErrorString(code) to retrieve the message associated with an error code. It returns None when the code does not correspond to an available error message. These additions make Expat parser errors accessible through the Python module’s public interface.

Populate the canonical error constants and bidirectional mappings, implement C-long-to-int ErrorString lookup, and restore the canonical metadata test through update_lib.

Assisted-by: OpenAI Codex: model version unavailable
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between a838216 and e09c4e8.

Files ignored due to path filters: 2
  • Lib/test/test_pyexpat.py is excluded by !Lib/**
  • Lib/test/test_xml_etree.py is excluded by !Lib/**
Files selected for processing: 1
  • crates/stdlib/src/pyexpat.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

The pyexpat.errors submodule now exposes Expat error constants and codes and messages dictionaries. The pyexpat module also provides ErrorString(code) to look up an error message.

Changes: pyexpat error metadata and lookup

Layer / File(s) Summary
Error metadata and lookup
crates/stdlib/src/pyexpat.rs
The module initializes and registers pyexpat.errors with Expat error constants and dictionaries. ErrorString(code) converts the input and returns the matching message, or None when the index is outside the table.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Possibly related issues

  • RustPython/RustPython#6839 — This change updates pyexpat error metadata as one part of the broader standard-library update tracked by the issue.

Suggested reviewers: youknowone, 1ndahous3

Merge Risk: Minimal · up to e09c4

No concrete merge-blocking issue is established for the pyexpat error-metadata changes. Mergeability remains subject to normal checks passing.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.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. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: implementing CPython 3.15 Expat public error metadata.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.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 3 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • 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

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

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

📦 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: 17)
[ ] 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: 39)
[x] test: cpython/Lib/test/test_sax.py (TODO: 25)
[x] test: cpython/Lib/test/test_xml_dom_minicompat.py
[x] test: cpython/Lib/test/test_xml_dom_xmlbuilder.py

dependencies:

  • xml

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

@codspeed

codspeed Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing youknowdot:python315-expat-errors-20261030 (e09c4e8) with main (2c51e7a)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Retire expected-failure markers demonstrated obsolete on macOS, Ubuntu and Windows by CI 41112774656, including ElementTree's inherited C variant. Restore both canonical methods via update_lib without changing assertions or other adaptations.

Assisted-by: OpenAI Codex: model version unavailable
@youknowone
youknowone marked this pull request as ready for review October 30, 2026 23:30
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-30T23:30:58.022606Z
We couldn’t complete this review. Comment @codex review to try again.
e09c4e8 Draft marked ready
ℹ️ 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.

@youknowone
youknowone enabled auto-merge (squash) October 30, 2026 23:31
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@youknowone
youknowone merged commit 4954aa7 into RustPython:main Oct 31, 2026
30 checks passed
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.

3 participants