Skip to content

v0.3.0: ElementTree read-only drop-in#2

Merged
cigrainger merged 1 commit intomainfrom
et-compat
Mar 27, 2026
Merged

v0.3.0: ElementTree read-only drop-in#2
cigrainger merged 1 commit intomainfrom
et-compat

Conversation

@cigrainger
Copy link
Copy Markdown
Contributor

Summary

Full read-only drop-in compatibility with xml.etree.ElementTree.

Element methods added

  • find(path), findall(path), iterfind(path), findtext(path, default) — ET path syntax translated to XPath
  • extend(), makeelement() — raise TypeError (read-only)

Element fixes

  • iter() now yields self first (matching stdlib)
  • itertext() now interleaves text/tail in correct stdlib order

ET module functions added

  • fromstringlist(), tostringlist(), dump(), iselement()
  • SubElement(), Comment(), ProcessingInstruction()/PI(), indent() — raise TypeError
  • register_namespace() — no-op for compatibility
  • ElementTree.iter(), .findtext(), .iterfind(), .write() (raises)

Test coverage

  • 49 new tests (240 total)
  • Cross-validation against stdlib on find/findall/findtext/iter/itertext/attrib/get/keys/items
  • Adversarial: empty docs, deep nesting, predicates, unicode, entities, leaf elements

What's NOT supported (by design)

  • TreeBuilder, XMLParser, XMLPullParser — incremental parsing
  • canonicalize — C14N serialization
  • Any mutation operation — clear TypeError with helpful message

🤖 Generated with Claude Code

@cigrainger cigrainger force-pushed the et-compat branch 11 times, most recently from 0095517 to 0d3bd0c Compare March 27, 2026 21:38
Element now has find(), findall(), iterfind(), findtext() — the core
ElementTree query API. Path syntax (tag, .//tag, *, .., [@attrib],
[tag='text']) is translated to XPath and evaluated by the SIMD engine.

Also adds:
- extend(), makeelement() on Element (raise TypeError)
- iter() now includes self (matching stdlib behavior)
- itertext() now yields text/tail in correct stdlib order
- ET module: fromstringlist, tostringlist, dump, iselement
- ET module: SubElement, Comment, PI, indent (raise TypeError)
- ET module: register_namespace (no-op), ElementTree.write (TypeError)
- ET module: ElementTree.iter, findtext, iterfind

131 new tests (322 total):
- 49 ET compat tests (parse, ElementTree class, find/findall, read-only)
- 82 exhaustive drop-in tests cross-validating every operation against
  stdlib xml.etree.ElementTree on 7 corpus types
- Property tests (Hypothesis) for iter, itertext, find, len, text/tail
- Adversarial: empty docs, deep nesting, entities, mixed content, CDATA

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@cigrainger cigrainger merged commit f8cb1ae into main Mar 27, 2026
13 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.

1 participant