Parsing incomplete XML raises TypeError: __init__() takes at least 5 positional arguments (2 given)

Bug #1980767 reported by Enrico Minack
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
Fix Released
Low
scoder

Bug Description

Parsing incomplete XML raises an XMLSyntaxError. But if a bespoke target is used, it fails to instantiate the error:

    from lxml import etree

    parser = etree.XMLParser(target=etree.TreeBuilder())
    etree.fromstring('<a><b></b>', parser=parser)

    TypeError: __init__() takes at least 5 positional arguments (2 given)

The following raises the error correctly:

    parser = etree.XMLParser()
    etree.fromstring('<a><b></b>', parser=parser)

    lxml.etree.XMLSyntaxError: Premature end of data in tag a line 1, line 1, column 11

It looks like TreeBuilder.close() calls (https://github.com/lxml/lxml/blob/master/src/lxml/saxparser.pxi#L820):

    raise XMLSyntaxAssertionError("missing end tags")

which calls the XMLSyntaxError constructor with only two arguments (self and message) and not the expected 5.

This issue also surfaces when any error is raised while processing the XML, which finally closes the TreeBuilder and throws another exception, because the processed XML has unclosed tags (as processing is half-way done).

Python : sys.version_info(major=3, minor=8, micro=13, releaselevel='final', serial=0)
lxml.etree : (4, 9, 1, 0)
libxml used : (2, 9, 14)
libxml compiled : (2, 9, 14)
libxslt used : (1, 1, 35)
libxslt compiled : (1, 1, 35)

Enrico Minack (enricomi)
description: updated
description: updated
Enrico Minack (enricomi)
description: updated
Revision history for this message
scoder (scoder) wrote :
Changed in lxml:
assignee: nobody → scoder (scoder)
importance: Undecided → Low
milestone: none → 5.0
status: New → Fix Committed
scoder (scoder)
Changed in lxml:
milestone: 5.0 → 4.9.4
scoder (scoder)
Changed in lxml:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.