iterwalk does not emit a start event for first element when tags are passed

Bug #1755825 reported by david greisen on 2018-03-14
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
Medium
scoder

Bug Description

Python : sys.version_info(major=3, minor=6, micro=3, releaselevel='final', serial=0)
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>Federal Laws</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(root_el, events=('start', 'end'), tag=tags)
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(root_el, events=('start', 'end'), tag=tags)
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(root_el, events=('start', 'end'), tag=tags)
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(root_el, events=('start', 'end'))
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

```

scoder (scoder) wrote :
Changed in lxml:
assignee: nobody → scoder (scoder)
importance: Undecided → Medium
status: New → Fix Committed
milestone: none → 4.2.1
scoder (scoder) on 2018-03-23
Changed in lxml:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers