]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-130999: Fix globals() poisoning in test_traceback (gh-135030)
authorŁukasz Langa <lukasz@langa.pl>
Mon, 2 Jun 2025 14:57:08 +0000 (16:57 +0200)
committerGitHub <noreply@github.com>
Mon, 2 Jun 2025 14:57:08 +0000 (16:57 +0200)
Lib/test/test_traceback.py

index 6b2271f5d5ba8d963adb23a0f120dd150ed4a15a..74b979d009664d9e4bdf2eb90df48a39d66f8180 100644 (file)
@@ -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)