You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesstdlibPython modules in the Lib dirtopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error
Adding a non-string key to globals() dict and then trying to print a non-defined variable crashes the interactive prompt.
How to reproduce
Start an interactive prompt for Python 3.13.1.
Use the dict.update() function on globals() to add a non-string key to the global variables dict.
Try printing a not-defined variable,
While raising the NameError exception, Python is unable to deal with the invalid key in globals(), which causes a crash.
Expected behavior dict.update() should behave differently for globals(), only allowing valid string names as keys. For invalid keys, a TypeError should be raised.
Interactive prompt
Python 3.13.1 (v3.13.1:06714517797, Dec 3 2024, 14:00:22) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> globals().update({123: 'test'})
>>> not_defined
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
NameError: name 'not_defined' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/_pyrepl/__main__.py", line 6, in <module>
__pyrepl_interactive_console()
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/_pyrepl/main.py", line 59, in interactive_console
run_multiline_interactive_console(console)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/_pyrepl/simple_interact.py", line 160, in run_multiline_interactive_console
more = console.push(_strip_final_indent(statement), filename=input_name, _symbol="single") # type: ignore[call-arg]
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/code.py", line 314, in push
more = self.runsource(source, filename, symbol=_symbol)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/_pyrepl/console.py", line 211, in runsource
self.runcode(code)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/code.py", line 96, in runcode
self.showtraceback()
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/code.py", line 129, in showtraceback
self._showtraceback(typ, value, tb.tb_next, '')
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/code.py", line 145, in _showtraceback
self._excepthook(typ, value, tb)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/_pyrepl/console.py", line 169, in _excepthook
lines = traceback.format_exception(
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/traceback.py", line 154, in format_exception
te = TracebackException(type(value), value, tb, limit=limit, compact=True)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/traceback.py", line 1090, in __init__
suggestion = _compute_suggestion_error(exc_value, exc_traceback, wrong_name)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/traceback.py", line 1524, in _compute_suggestion_error
return _suggestions._generate_suggestions(d, wrong_name)
TypeError: all elements in 'candidates' must be strings
CPython versions tested on:
3.13
Operating systems tested on:
macOS
Output from running 'python -VV' on the command line:
Python 3.13.1 (v3.13.1:06714517797, Dec 3 2024, 14:00:22) [Clang 15.0.0 (clang-1500.3.9.4)]
The text was updated successfully, but these errors were encountered:
Eclips4
added
type-bug
An unexpected behavior, bug, or error
topic-repl
Related to the interactive shell
3.13
bugs and security fixes
3.14
bugs and security fixes
3.15
new features, bugs and security fixes
and removed
type-crash
A hard crash of the interpreter, possibly with a core dump
type-bug
An unexpected behavior, bug, or error
topic-repl
Related to the interactive shell
labels
May 9, 2025
I think we can just raise the error when someone attempts to insert an invalid value, I doubt there are backwards compatibility concerns. Unless we want to catch the errors (safer for backwards compatibility)?
picnixz
changed the title
Adding a non-string key to globals() dict makes it possible to crash the interactive prompt
REPL does not handle TypeError raised from _suggestions._generate_suggestionsMay 9, 2025
3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesstdlibPython modules in the Lib dirtopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error
Uh oh!
There was an error while loading. Please reload this page.
Crash report
What happened?
Adding a non-string key to globals() dict and then trying to print a non-defined variable crashes the interactive prompt.
How to reproduce
dict.update()
function onglobals()
to add a non-string key to the global variables dict.NameError
exception, Python is unable to deal with the invalid key inglobals()
, which causes a crash.Expected behavior
dict.update()
should behave differently forglobals()
, only allowing valid string names as keys. For invalid keys, aTypeError
should be raised.Interactive prompt
CPython versions tested on:
3.13
Operating systems tested on:
macOS
Output from running 'python -VV' on the command line:
Python 3.13.1 (v3.13.1:06714517797, Dec 3 2024, 14:00:22) [Clang 15.0.0 (clang-1500.3.9.4)]
The text was updated successfully, but these errors were encountered: