Move namespace setup inside the template.
This commit is contained in:
parent
ba7b560c1d
commit
843a751369
|
@ -234,6 +234,12 @@ class OrderedDict(dict):
|
|||
################################################################################
|
||||
|
||||
_class_template = '''\
|
||||
__name__ = 'namedtuple_{typename}'
|
||||
|
||||
from builtins import property as _property, tuple as _tuple
|
||||
from operator import itemgetter as _itemgetter
|
||||
from collections import OrderedDict
|
||||
|
||||
class {typename}(tuple):
|
||||
'{typename}({arg_list})'
|
||||
|
||||
|
@ -349,8 +355,7 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
|
|||
|
||||
# Execute the class definition string in a temporary namespace and
|
||||
# support tracing utilities by setting a value for frame.f_globals['__name__']
|
||||
namespace = dict(_itemgetter=_itemgetter, __name__='namedtuple_%s' % typename,
|
||||
OrderedDict=OrderedDict, _property=property, _tuple=tuple)
|
||||
namespace = {}
|
||||
try:
|
||||
exec(class_definition, namespace)
|
||||
except SyntaxError as e:
|
||||
|
|
Loading…
Reference in New Issue