Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-94808: Coverage: __build_class__ inside a non-dict __builtins__ #95932

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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