--- collections.py.tmp 2008-05-18 03:58:01.000000000 +0200 +++ collections.py 2008-05-18 04:19:56.000000000 +0200 @@ -89,7 +89,9 @@ print template # Execute the template string in a temporary namespace - namespace = dict(itemgetter=_itemgetter) + # Some tracers access frame.f_globals["__name__"] to get the module name + # Putting something in __name__ will avoid a crash in tracer code + namespace = dict(itemgetter=_itemgetter, __name__='__generated_%s__' % typename) try: exec template in namespace except SyntaxError, e: @@ -97,10 +99,13 @@ result = namespace[typename] # For pickling to work, the __module__ variable needs to be set to the frame - # where the named tuple is created. Bypass this step in enviroments where - # sys._getframe is not defined (Jython for example). + # where the named tuple is created. namespace['__name__'] will be even more + # useful for tracing purposes if it also contains the module name. Bypass + # this step in enviroments where sys._getframe is not defined (Jython for + # example). if hasattr(_sys, '_getframe'): result.__module__ = _sys._getframe(1).f_globals['__name__'] + namespace['__name__'] = '__generated_%s__%s__' % (typename, result.__module__) return result