diff options
author | Raymond Hettinger <python@rcn.com> | 2011-03-24 03:33:30 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2011-03-24 03:33:30 (GMT) |
commit | f6d3e8eaef83c82416c2ca9d639ed59beba1f877 (patch) | |
tree | 18ad65b96e2635fe4ca08e61ce7c783777e3b9f3 /Lib/collections | |
parent | 5d43cff62373f8405765faeef48f0bd2ccc22d9b (diff) | |
download | cpython-f6d3e8eaef83c82416c2ca9d639ed59beba1f877.zip cpython-f6d3e8eaef83c82416c2ca9d639ed59beba1f877.tar.gz cpython-f6d3e8eaef83c82416c2ca9d639ed59beba1f877.tar.bz2 |
Add tests for _source to importable and exec'able.
Move __name__ back out of the template; the responsibility
for setting __name__ lies with the caller (which knows
something about the new namespace), not with the class
definition (which doesn't know about the namespace it is
being built in).
Diffstat (limited to 'Lib/collections')
-rw-r--r-- | Lib/collections/__init__.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 5f11f6a..122dfb6 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -234,8 +234,6 @@ 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 @@ -353,8 +351,9 @@ def namedtuple(typename, field_names, verbose=False, rename=False): for index, name in enumerate(field_names)) ) - # Execute the class definition string in a temporary namespace - namespace = {} + # Execute the template string in a temporary namespace and + # support tracing utilities by setting a value for frame.f_globals['__name__'] + namespace = dict(__name__='namedtuple_%s' % typename) try: exec(class_definition, namespace) except SyntaxError as e: |