Bug report
Bug description:
The ParseError class from the xml module does not cast the msg attribute to str when running on the pure-Python version, here is a MRE:
import xml.etree.ElementTree as etree
try:
etree.XML("<")
except etree.ParseError as e:
print("XMLParser:", etree.XMLParser)
print("args:", e.args)
print("msg:", repr(e.msg))
print("msg type:", type(e.msg))
On regular CPython using the C-accelerator:
XMLParser: <class 'xml.etree.ElementTree.XMLParser'>
args: ('unclosed token: line 1, column 0',)
msg: 'unclosed token: line 1, column 0'
msg type: <class 'str'>
If you force the execution of the Python module:
XMLParser: <class 'xml.etree.ElementTree.XMLParser'>
args: (ExpatError('unclosed token: line 1, column 0'),)
msg: ExpatError('unclosed token: line 1, column 0')
msg type: <class 'pyexpat.ExpatError'>
The issue is this function:
def _raiseerror(self, value):
err = ParseError(value)
err.code = value.code
err.position = value.lineno, value.offset
raise err
At all call sites, value is an exception, so effectively the first argument is always an exception. Note that ParseError is a sub-class of SyntaxError.
In the C-version, the first agument is always cast to a str.
I encountered this bug through PyPy that use the Python version of lxml.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
Bug report
Bug description:
The
ParseErrorclass from thexmlmodule does not cast the msg attribute tostrwhen running on the pure-Python version, here is a MRE:On regular CPython using the C-accelerator:
If you force the execution of the Python module:
The issue is this function:
At all call sites,
valueis an exception, so effectively the first argument is always an exception. Note thatParseErroris a sub-class ofSyntaxError.In the C-version, the first agument is always cast to a str.
I encountered this bug through PyPy that use the Python version of
lxml.CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs