iterwalk does not emit a start event for first element when tags are passed
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Fix Released
|
Medium
|
scoder |
Bug Description
Python : sys.version_
lxml.etree : (4, 2, 0, 0)
libxml used : (2, 9, 8)
libxml compiled : (2, 9, 8)
libxslt used : (1, 1, 32)
libxslt compiled : (1, 1, 32)
```
xml = """
<library>
<heading>D.C. Law Library</heading>
<collection name="dclaws">
<heading>D.C. Laws</heading>
</collection>
<collection name="fedlaws">
<heading>
</collection>
</library>
"""
import lxml.etree as et
root_el = et.fromstring(xml)
#INCORRECT - first element matches a passed tag
tags = ('library',)
walker = et.iterwalk(
for event, el in walker:
print(event, el.tag)
# end library # <- missing `start library`!
# INCORRECT - first element matches a passed tag
tags = ('collection', 'library')
walker = et.iterwalk(
for event, el in walker:
print(event, el.tag)
# start collection # <- missing `start library`!
# end collection
# start collection
# end collection
# end library
# CORRECT - first element does not match a passed tag
tags = ('collection',)
walker = et.iterwalk(
for event, el in walker:
print(event, el.tag)
# start collection
# end collection
# start collection
# end collection
#CORRECT - no tags passed to iterwalk
walker = et.iterwalk(
for event, el in walker:
print(event, el.tag)
# start library
# start heading
# end heading
# start collection
# start heading
# end heading
# end collection
# start collection
# start heading
# end heading
# end collection
# end library
```
Changed in lxml: | |
status: | Fix Committed → Fix Released |
Interesting, non-obvious bug. Fixed here: /github. com/lxml/ lxml/commit/ b398c5162867b2f 994acca7572d3a1 51e6749f6c
https:/