From: Ɓukasz Langa Date: Mon, 2 Jun 2025 14:57:08 +0000 (+0200) Subject: gh-130999: Fix globals() poisoning in test_traceback (gh-135030) X-Git-Tag: v3.15.0a1~1412 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=055827528fa50c9a7707792f5fe264c4e20c07e9;p=thirdparty%2FPython%2Fcpython.git gh-130999: Fix globals() poisoning in test_traceback (gh-135030) --- diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 6b2271f5d5ba..74b979d00966 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -4232,8 +4232,8 @@ class SuggestionFormattingTestBase: return mod_name - def get_import_from_suggestion(self, mod_dict, name): - modname = self.make_module(mod_dict) + def get_import_from_suggestion(self, code, name): + modname = self.make_module(code) def callable(): try: @@ -4416,8 +4416,9 @@ class SuggestionFormattingTestBase: def test_name_error_suggestions_with_non_string_candidates(self): def func(): abc = 1 - globals()[0] = 1 - abv + custom_globals = globals().copy() + custom_globals[0] = 1 + print(eval("abv", custom_globals, locals())) actual = self.get_suggestion(func) self.assertIn("abc", actual)