Skip to content

🐛 fix(etree): resolve absolute XPath in standalone trees - #2560

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/etree-absolute-xpath
Nov 23, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/etree-absolute-xpath

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

/div now selects the root even when called from a descendant in a tree built with Element and SubElement or returned as a single-element fragment by fragment_fromstring. In both cases, //h1 inside a predicate can find an h1 elsewhere in the same tree.

The etree adapter gives these trees an implicit document. XPath uses it for absolute paths and keeps the calling element as context for relative steps. The implicit document can also hold text after the root element, so serialization still includes that tail.

Fixes #2555

Standalone elements have an implicit document in lxml. Give constructed
trees and single-element fragments a root for XPath to resolve, while
preserving the calling element as context for relative steps.

Fixes tox-dev#2555
@gaborbernat gaborbernat added the bug Something isn't working label Nov 23, 2026
@codspeed

codspeed Bot commented Nov 23, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 580 untouched benchmarks
⏩ 91 skipped benchmarks1


Comparing gaborbernat:fix/etree-absolute-xpath (9096808) with main (b1a08a2)

Open in CodSpeed

Footnotes

  1. 91 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. ↩

@gaborbernat
gaborbernat merged commit e48116f into tox-dev:main Nov 23, 2026
66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

etree: absolute XPath on Element/SubElement and fragment trees

1 participant