Skip to content

Commit

Permalink
GH-94808: Test __build_class__ inside non-dict __builtins__ (GH-95932)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom authored Aug 15, 2022
1 parent 914f636 commit 3adb4d8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,11 +737,6 @@ def test_exec_globals(self):
self.assertRaises(TypeError,
exec, code, {'__builtins__': 123})

# no __build_class__ function
code = compile("class A: pass", "", "exec")
self.assertRaisesRegex(NameError, "__build_class__ not found",
exec, code, {'__builtins__': {}})

class frozendict_error(Exception):
pass

Expand All @@ -758,6 +753,15 @@ def __setitem__(self, key, value):
self.assertRaises(frozendict_error,
exec, code, {'__builtins__': frozen_builtins})

# no __build_class__ function
code = compile("class A: pass", "", "exec")
self.assertRaisesRegex(NameError, "__build_class__ not found",
exec, code, {'__builtins__': {}})
# __build_class__ in a custom __builtins__
exec(code, {'__builtins__': frozen_builtins})
self.assertRaisesRegex(NameError, "__build_class__ not found",
exec, code, {'__builtins__': frozendict()})

# read-only globals
namespace = frozendict({})
code = compile("x=1", "test", "exec")
Expand Down

0 comments on commit 3adb4d8

Please sign in to comment.