[issue38611] Bug in traceback.py

Jim Carroll report at bugs.python.org
Mon Oct 28 05:11:15 EDT 2019


New submission from Jim Carroll <jim at carroll.com>:

_elementtree.c defines a custom exception 'xml.etree.ElementTree.ParseError' that inherits from SyntaxError. According to the docs https://docs.python.org/3/library/exceptions.html#SyntaxError

``Instances of this class have attributes filename, lineno, offset and text for easier access to the details.``

The ElementTree.Parser does not provide these extra attributes. While unittesting a badly formatted string passed to ET.fromstring(), the unittests/results.py module passes the exception to traceback.py, which attempts to extract the members causing it to raise a new exception.

Either ElementTree.Parser should be raising something other than SyntaxErrors, or it should be providing the required attributes, or traceback.py needs to be more flexible and test for the extra attributes before accessing.

I'm willing to submit a patch, but before diving in, wasn't sure which path people would prefer to see fixed?

The code in traceback.py is from lines 516 - 521.

----------
components: Library (Lib)
messages: 355518
nosy: jamercee
priority: normal
severity: normal
status: open
title: Bug in traceback.py
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38611>
_______________________________________


More information about the Python-bugs-list mailing list