From 843a751369856f97f936c94a562b461254941b35 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 23 Mar 2011 11:49:56 -0700 Subject: [PATCH] Move namespace setup inside the template. --- Lib/collections/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index d4e8ed60fa4..b75b4d73083 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -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: