Deny eval() direct access to builtins (GH-20713)

This commit is contained in:
Raymond Hettinger 2020-06-07 23:51:40 -07:00 committed by GitHub
parent 7633371dac
commit 3ff51d425e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -407,7 +407,8 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non
# Create all the named tuple methods to be added to the class namespace # Create all the named tuple methods to be added to the class namespace
s = f'lambda _cls, {arg_list}: _tuple_new(_cls, ({arg_list}))' s = f'lambda _cls, {arg_list}: _tuple_new(_cls, ({arg_list}))'
namespace = {'_tuple_new': tuple_new, '__name__': f'namedtuple_{typename}'} namespace = {'_tuple_new': tuple_new, '__builtins__': None,
'__name__': f'namedtuple_{typename}'}
__new__ = eval(s, namespace) __new__ = eval(s, namespace)
__new__.__doc__ = f'Create new instance of {typename}({arg_list})' __new__.__doc__ = f'Create new instance of {typename}({arg_list})'
if defaults is not None: if defaults is not None: