Closed
Description
Bug report
Bug description:
Hi.
I noticed that using add_note()
with an error of type SyntaxError
(or its derived such as IndentationError
and TabError
) produces a traceback without the expected notes.
Here is a minimal reproducible example:
try:
exec("a = 7 *")
except SyntaxError as e:
e.add_note("Note")
raise
Or alternatively:
e = SyntaxError("invalid syntax", ("<string>", 1, 8, "a = 7 *\n", 1, 8))
e.add_note("Note")
raise e
The output of these examples is:
Traceback (most recent call last):
File "/home/delgan/test.py", line 2, in <module>
exec("a = 7 *")
File "<string>", line 1
a = 7 *
^
SyntaxError: invalid syntax
The expected "Note"
is missing.
Since neither PEP 678 nor the documentation mention that SyntaxError
is not fully compatible with notes, I assume that this is probably a bug.
CPython versions tested on:
3.11, 3.12
Operating systems tested on:
Linux