Skip to content

Commit

Permalink
pythonGH-94808: Test __build_class__ inside non-dict __builtins__ (py…
Browse files Browse the repository at this point in the history
…thonGH-95932)

(cherry picked from commit 3adb4d8)

Co-authored-by: Michael Droettboom <[email protected]>
  • Loading branch information
mdboom authored and miss-islington committed Aug 15, 2022
1 parent 3fa97b8 commit 0889e30
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 0889e30

Please sign in to comment.