Skip to content

Commit 3e18a3c

Browse files
ambvPranjal095
authored andcommitted
pythongh-130999: Fix globals() poisoning in test_traceback (pythongh-135030)
1 parent 3d9658a commit 3e18a3c

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
@@ -4271,8 +4271,8 @@ def make_module(self, code):
42714271

42724272
return mod_name
42734273

4274-
def get_import_from_suggestion(self, mod_dict, name):
4275-
modname = self.make_module(mod_dict)
4274+
def get_import_from_suggestion(self, code, name):
4275+
modname = self.make_module(code)
42764276

42774277
def callable():
42784278
try:
@@ -4455,8 +4455,9 @@ def func():
44554455
def test_name_error_suggestions_with_non_string_candidates(self):
44564456
def func():
44574457
abc = 1
4458-
globals()[0] = 1
4459-
abv
4458+
custom_globals = globals().copy()
4459+
custom_globals[0] = 1
4460+
print(eval("abv", custom_globals, locals()))
44604461
actual = self.get_suggestion(func)
44614462
self.assertIn("abc", actual)
44624463

0 commit comments

Comments
 (0)