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: