Absolute path allowed from ElementTree but fails to find root element
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Fix Released
|
Low
|
scoder |
Bug Description
While absolute ElementPaths are forbidden on Element, lxml does allow them on ElementTree. However they are incorrect, as they fail to find the root element itself (unlike xpath).
CPython's elementtree has a similar issue however it triggers a FutureWarning
Test script:
```
import contextlib
from xml.etree import ElementTree as ET
from lxml import etree
doc = ET.fromstring(
# raises SyntaxError
with contextlib.
print(
raise Exception()
# triggers FutureWarning: This search is broken in 1.3 and earlier, and will be fixed in a future version.
# does not find anything
print(ET.
doc = etree.fromstrin
# raises SyntaxError
with contextlib.
print(
raise Exception()
# doesn't find anything, no warning
print(doc.
# by comparison xpath finds the root, whether from an Element or an
# ElementTree
print(doc.
print(doc.
```
system info:
Python : sys.version_
lxml.etree : (4, 9, 3, 0)
libxml used : (2, 10, 3)
libxml compiled : (2, 10, 3)
libxslt used : (1, 1, 38)
libxslt compiled : (1, 1, 38)
Changed in lxml: | |
status: | Fix Committed → Fix Released |
assignee: | nobody → scoder (scoder) |
I agree that this is incorrect. I added the same FutureWarning as in Python's xml.etree. Changing this requires a deprecation period, and preferably CPython going there first.
https:/ /github. com/lxml/ lxml/commit/ 3a8caecc0f94d8e 00ab116a4b32e57 675140eb4d