-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
raise SyntaxError('hello', 'abcdef')
crashes the new Python 3.13 REPL
#128894
Labels
3.13
bugs and security fixes
3.14
new features, bugs and security fixes
topic-repl
Related to the interactive shell
type-bug
An unexpected behavior, bug, or error
Comments
brettcannon
changed the title
"raise SyntaxError('hello', 'abcdef')" crashes the new Python 3.13 REPL
Jan 15, 2025
raise SyntaxError('hello', 'abcdef')
crashes the new Python 3.13 REPL
ZeroIntensity
added
3.13
bugs and security fixes
3.14
new features, bugs and security fixes
labels
Jan 16, 2025
New REPL is not directly the cause of this problem. It also happens with an old REPL:
This is related to e733136 Bisected to that commit. Commits before that - work correctly. I am working on the fix 👍 CC @pablogsal as the commit author |
diff --git Lib/traceback.py Lib/traceback.py
index 6367c00e4d4..4f945630c8b 100644
--- Lib/traceback.py
+++ Lib/traceback.py
@@ -1283,7 +1283,7 @@ def _format_syntax_error(self, stype, **kwargs):
filename_suffix = ' ({})'.format(self.filename)
text = self.text
- if text is not None:
+ if isinstance(text, str):
# text = " foo\n"
# rtext = " foo"
# ltext = "foo"
@@ -1292,10 +1292,17 @@ def _format_syntax_error(self, stype, **kwargs):
spaces = len(rtext) - len(ltext)
if self.offset is None:
yield ' {}\n'.format(ltext)
- else:
+ elif isinstance(self.offset, int):
offset = self.offset
if self.lineno == self.end_lineno:
- end_offset = self.end_offset if self.end_offset not in {None, 0} else offset
+ end_offset = (
+ self.end_offset
+ if (
+ isinstance(self.end_offset, int)
+ and self.end_offset != 0
+ )
+ else offset
+ )
else:
end_offset = len(rtext) + 1
@pablogsal what do you think about this solution? All tests pass, including a new one. |
sobolevn
added a commit
to sobolevn/cpython
that referenced
this issue
Jan 17, 2025
…or` on custom `SyntaxError` metadata
sobolevn
added a commit
to sobolevn/cpython
that referenced
this issue
Jan 17, 2025
…or` on custom `SyntaxError` metadata
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
3.13
bugs and security fixes
3.14
new features, bugs and security fixes
topic-repl
Related to the interactive shell
type-bug
An unexpected behavior, bug, or error
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
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
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:
SyntaxError
to make sure that the types are those expected (str
for filename,int
for lineno, etc.)SyntaxError
instances 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_error
on customSyntaxError
metadata #128946The text was updated successfully, but these errors were encountered: