diff options
author | Raymond Hettinger <python@rcn.com> | 2011-03-23 18:49:56 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2011-03-23 18:49:56 (GMT) |
commit | 843a751369856f97f936c94a562b461254941b35 (patch) | |
tree | 4f73cf5f6bfd92f0399f232f83c1bdcaf79a8a69 /Lib/collections | |
parent | ba7b560c1d3aca8dac21e824c7d4a11e7f584e76 (diff) | |
download | cpython-843a751369856f97f936c94a562b461254941b35.zip cpython-843a751369856f97f936c94a562b461254941b35.tar.gz cpython-843a751369856f97f936c94a562b461254941b35.tar.bz2 |
Move namespace setup inside the template.
Diffstat (limited to 'Lib/collections')
-rw-r--r-- | Lib/collections/__init__.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index d4e8ed6..b75b4d7 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: |