From: Raymond Hettinger Date: Wed, 23 Mar 2011 18:49:56 +0000 (-0700) Subject: Move namespace setup inside the template. X-Git-Tag: v3.3.0a1~2782 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=843a751369856f97f936c94a562b461254941b35;p=python Move namespace setup inside the template. --- diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index d4e8ed60fa..b75b4d7308 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: