Skip to content

Commit 0558275

Browse files
authored
gh-130999: Fix globals() poisoning in test_traceback (gh-135030)
1 parent 26a1cd4 commit 0558275

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Lib/test/test_traceback.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4232,8 +4232,8 @@ def make_module(self, code):
42324232

42334233
return mod_name
42344234

4235-
def get_import_from_suggestion(self, mod_dict, name):
4236-
modname = self.make_module(mod_dict)
4235+
def get_import_from_suggestion(self, code, name):
4236+
modname = self.make_module(code)
42374237

42384238
def callable():
42394239
try:
@@ -4416,8 +4416,9 @@ def func():
44164416
def test_name_error_suggestions_with_non_string_candidates(self):
44174417
def func():
44184418
abc = 1
4419-
globals()[0] = 1
4420-
abv
4419+
custom_globals = globals().copy()
4420+
custom_globals[0] = 1
4421+
print(eval("abv", custom_globals, locals()))
44214422
actual = self.get_suggestion(func)
44224423
self.assertIn("abc", actual)
44234424

0 commit comments

Comments
 (0)