From ec0c35e6acac1b75e9d1691e71ddde7f69375094 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 12 Aug 2022 14:08:44 -0400 Subject: [PATCH] gh-94808: Coverage: __build_class__ inside a non-dict __builtins__ --- Lib/test/test_builtin.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index d5eaf291a5ca28..6fa5ea67c8b399 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -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 @@ -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")