Example 1 (broken)
Input:
>>> exec('"')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
"
^
SyntaxError: EOL while scanning string literal
Result:

👆 Notice the two missing lines in the output, starting with the Traceback (most recent call last): line. This is a "real" traceback generated by the Python 3.9 REPL.
Example 2 (okay)
Adding a module location to the 2nd file location (, in <module>) restores the missing "Traceback ..." line and renders as expected:
>>> exec('"')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
"
^
SyntaxError: EOL while scanning string literal
Result:

Adding a comma (,) after the 2nd File "<string>", line 1 is enough to make the "Traceback ..." line appear (although it won't get the correct highlighting):

Versions