Repository navigation
Implement pyexpat ordered_attributes - #8305
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (3)
📒 Files selected for processing (1)
📝 WalkthroughWalkthroughStart-element attribute handling now checks ChangesXML attribute handling
Estimated code review effort: 2 (Simple) | ~10 minutes 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)
[x] lib: cpython/Lib/test/libregrtest dependencies:
dependent tests: (no tests depend on regrtest) Legend:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes RustPython’s pyexpat parser to honor the ordered_attributes flag: when enabled, StartElementHandler receives a flat [name, value, ...] list in document order (matching CPython), instead of always receiving a dict. This restores correct behavior for stdlib consumers like xml.etree.ElementTree and xml.dom.minidom that rely on ordered attributes.
Changes:
- Implemented
ordered_attributeshandling inpyexpatstart-element dispatch (list vs dict). - Removed
@unittest.expectedFailuremarkers fromtest_xml_etreeandtest_minidomtests that now pass.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
crates/stdlib/src/pyexpat.rs |
Implements list-vs-dict attribute container based on ordered_attributes. |
Lib/test/test_xml_etree.py |
Removes expected-failure decorators for ElementTree tests now passing. |
Lib/test/test_minidom.py |
Removes expected-failure decorators for minidom tests now passing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let ordered = self | ||
| .ordered_attributes | ||
| .read() | ||
| .clone() | ||
| .is_true(vm) | ||
| .unwrap_or(false); |
There was a problem hiding this comment.
@fanninpm, yes—Copilot’s comment is correct.
create_bool_property! normalizes every assignment via is_true() and stores a newly created canonical bool, while the constructor initializes ordered_attributes to False. Therefore, checking identity with vm.ctx.true_value is sufficient:
let ordered = self.ordered_attributes.read().is(&vm.ctx.true_value);This also avoids the redundant clone and prevents silently treating a hypothetical truthiness error as false.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/stdlib/src/pyexpat.rs`:
- Around line 358-363: In the ordered attribute handling, split the
`self.ordered_attributes.read().clone()` operation from the subsequent
`is_true(vm)` call so the `PyRwLockReadGuard` is dropped before executing Python
code. Update the `ordered` calculation near `is_true(vm)` to use the cloned
value, following the safe pattern in `invoke_handler`.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 62d0e65a-e5d3-4de9-a313-d4135c03d048
⛔ Files ignored due to path filters (2)
Lib/test/test_minidom.pyis excluded by!Lib/**Lib/test/test_xml_etree.pyis excluded by!Lib/**
📒 Files selected for processing (1)
crates/stdlib/src/pyexpat.rs
28ffe9d to
a347bcb
Compare
159404e to
fb1fce0
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/stdlib/src/pyexpat.rs`:
- Line 359: Update the ordered_attributes handling in the surrounding method to
clone the stored attribute reference before evaluating it, ensuring the read
guard is released before truthiness evaluation. Replace the strict
true-singleton identity check with the VM’s normal truthiness conversion so
values such as integer 1 remain truthy while avoiding the deadlock.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: cae68bbd-0a15-4422-ba1a-868a393086e7
⛔ Files ignored due to path filters (2)
Lib/test/test_minidom.pyis excluded by!Lib/**Lib/test/test_xml_etree.pyis excluded by!Lib/**
📒 Files selected for processing (1)
crates/stdlib/src/pyexpat.rs
|
There's also an unexpected success in |
When `ordered_attributes` is set, report attributes to the
StartElementHandler as a flat `[name, value, ...]` list matching
CPython's my_StartElementHandler, instead of always passing a dict.
`xml.etree.ElementTree` and `xml.dom.minidom` (via expatbuilder) both
enable this flag and rely on the flat-list contract, so parsing any
element with attributes previously failed: the dict made `_start` do
integer indexing, raising KeyError which was silently swallowed by the
handler invoker, leaving the tree empty ("missing toplevel element").
Reference (CPython 3.14):
https://github.com/python/cpython/blob/3.14/Modules/pyexpat.c#L439-L443
Remove `@unittest.expectedFailure` from tests that now pass
(23 in test_xml_etree, 15 in test_minidom, 1 in test_regrtest).
Assisted-by: Claude:claude-opus-4-8
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
fb1fce0 to
437b912
Compare
moreal
left a comment
There was a problem hiding this comment.
It seems related with https://github.com/python/cpython/blob/323c59a5e348347be2ce2b7ea55fcb30bf68b2d3/Modules/pyexpat.c#L430-L497 lines in CPython.
It removed so many @unittest.expectedFailure marks. Thank you!
youknowone
left a comment
There was a problem hiding this comment.
great! you break a core blocker
When `ordered_attributes` is set, report attributes to the
StartElementHandler as a flat `[name, value, ...]` list matching
CPython's my_StartElementHandler, instead of always passing a dict.
`xml.etree.ElementTree` and `xml.dom.minidom` (via expatbuilder) both
enable this flag and rely on the flat-list contract, so parsing any
element with attributes previously failed: the dict made `_start` do
integer indexing, raising KeyError which was silently swallowed by the
handler invoker, leaving the tree empty ("missing toplevel element").
Reference (CPython 3.14):
https://github.com/python/cpython/blob/3.14/Modules/pyexpat.c#L439-L443
Remove `@unittest.expectedFailure` from tests that now pass
(23 in test_xml_etree, 15 in test_minidom, 1 in test_regrtest).
Assisted-by: Claude:claude-opus-4-8
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Summary
pyexpatignored theordered_attributesflag and always passed theStartElementHandlera dict. Butxml.etree.ElementTree(andxml.dom.minidomviaexpatbuilder) setordered_attributes = 1andexpect a flat
[name, value, ...]list. The mismatch made_startinteger-index a dict, raising
KeyError, which the handler invokerswallowed — so parsing any element with an attribute silently failed
(e.g.
ET.XML('<a b="c"/>')raised"missing toplevel element").This honors the flag, matching CPython's
my_StartElementHandler:https://github.com/python/cpython/blob/3.14/Modules/pyexpat.c#L439-L443
ordered_attributestrue → flat list[name, value, ...](document order preserved)Only two consumers in the stdlib enable the flag —
xml.etree.ElementTreeand
xml.dom.minidom— and both rely on the list contract, so the changeis confined to them; the
elsebranch is byte-identical to the previousbehavior.
Test Plan
@unittest.expectedFailurefrom tests that now pass(23 in
test_xml_etree, 15 intest_minidom).test_xml_etree,test_minidom,test_pyexpat(and
test_sax,test_plistlibunaffected — no new failures orunexpected successes).
Summary by CodeRabbit