Bug report
Bug description:
In we enter this in the new interactive interpreter in Python 3.13
raise SyntaxError('hello', 'abcdef')
the interpreter window closes without any error message.
This happens because the second argument of SyntaxError is interpreted as an iterator that produces (filename, lineno, offset, text, end_lineno, end_offset). The constructor doesn't control if offset is an integer; in the example above it is set to the character 'c'.
When an exception is caught by the REPL it is handled by the traceback module. This line
|
if self.text and offset > len(self.text): |
compares the offset and an integer. This raises an exception which is not caught and makes the program crash.
There are 2 solutions to this issue:
- add more controls on the second argument to
SyntaxError to make sure that the types are those expected (str for filename, int for lineno, etc.)
- test the type of
SyntaxError instances arguments in traceback.py
This issue doesn't happen with previous versions of the REPL
Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct 2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> raise SyntaxError('hello', 'abcdef')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SyntaxError: hello (a)
>>>
CPython versions tested on:
3.13
Operating systems tested on:
Windows
Linked PRs
Bug report
Bug description:
In we enter this in the new interactive interpreter in Python 3.13
the interpreter window closes without any error message.
This happens because the second argument of
SyntaxErroris interpreted as an iterator that produces (filename, lineno, offset, text, end_lineno, end_offset). The constructor doesn't control if offset is an integer; in the example above it is set to the character 'c'.When an exception is caught by the REPL it is handled by the traceback module. This line
cpython/Lib/traceback.py
Line 1302 in 36c5e3b
compares the offset and an integer. This raises an exception which is not caught and makes the program crash.
There are 2 solutions to this issue:
SyntaxErrorto make sure that the types are those expected (strfor filename,intfor lineno, etc.)SyntaxErrorinstances arguments in traceback.pyThis issue doesn't happen with previous versions of the REPL
CPython versions tested on:
3.13
Operating systems tested on:
Windows
Linked PRs
TracebackException._format_syntax_erroron customSyntaxErrormetadata #128946TracebackException._format_syntax_erroron customSyntaxErrormetadata (GH-128946) #129178