QName doesn't work with iterators
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Fix Released
|
Medium
|
Unassigned |
Bug Description
The documentation of QName (https:/
> You can pass QName objects wherever a tag name is expected.
The signature of `_Element.iter` is defined as:
> iter(self, tag=None, *tags)
from this one would expect to pass a QName directly to iter would work and filter on that qname, however
t = etree.fromstrin
for node in t.iter(QName('http://
...
instead of doing nothing raises "TypeError: 'lxml.etree.QName' object is not iterable".
Workaround: str(QName(...)) but that's not great, and the documentation is still not correct.
Environment:
Python : sys.version_
lxml.etree : (4, 5, 0, 0)
libxml used : (2, 9, 10)
libxml compiled : (2, 9, 10)
libxslt used : (1, 1, 34)
libxslt compiled : (1, 1, 34)
description: | updated |
Changed in lxml: | |
importance: | Low → Medium |
milestone: | none → 4.5.1 |
status: | Triaged → Fix Committed |
Changed in lxml: | |
status: | Fix Committed → Fix Released |
Ah, yes, thanks for the report. The MultiTagMatcher needs to unpack QNames here:
https:/ /github. com/lxml/ lxml/blob/ 41cc5f378e2454f f1cabe5d227242c ce211a3a2b/ src/lxml/ etree.pyx# L2720
I would just let it create the string and recurse. This is not performance critical at all.
PR welcome, including tests, which should go near the".iter()" tests in "test_etree.py".