Skip to content

raise SyntaxError('hello', 'abcdef') crashes the new Python 3.13 REPL #128894

Closed
@PierreQuentel

Description

@PierreQuentel

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

Metadata

Metadata

Assignees

Labels

3.13bugs and security fixes3.14bugs and security fixestopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions