[New-bugs-announce] [issue2903] Add __name__ in globals of generated namedtuple namespace

Guillaume Knispel report at bugs.python.org
Sun May 18 05:12:32 CEST 2008

New submission from Guillaume Knispel <gknispel at proformatique.com>:

Some 3rd party tracers rely on frame.f_globals["__name__"] to be set to
the module name that contains the code currently executed.
frame.f_globals["__name__"] is not defined when some code has been
generated with exec, which is the way namedtuples are created.

The attached patch set __name__ to '__generated_%s__' % typename in the
generated namespace, which is quite handy to see where the code comes
from. Indeed if sys._getframe is available it sets __name__ to
'__generated_%s__%s__' % (typename, result.__module__) which is even
more useful.

components: Library (Lib)
files: collections.r59898.patch
keywords: patch
messages: 67022
nosy: xilun
severity: normal
status: open
title: Add __name__ in globals of generated namedtuple namespace
versions: Python 2.6
Added file: http://bugs.python.org/file10361/collections.r59898.patch

Tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list