]> granicus.if.org Git - python/commitdiff
Issue 5021: doctest.testfile should set __name__
authorRaymond Hettinger <python@rcn.com>
Tue, 27 Jan 2009 10:03:04 +0000 (10:03 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 27 Jan 2009 10:03:04 +0000 (10:03 +0000)
Lib/collections.py
Misc/NEWS

index effae7dd8db734888edd512be5418af08467b66f..0fddb97f9fc41742c34e1d6340ce11ec5666e86a 100644 (file)
@@ -109,7 +109,7 @@ def namedtuple(typename, field_names, verbose=False):
     # where the named tuple is created.  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__']
+        result.__module__ = _sys._getframe(1).f_globals.get('__name__', '__main__')
 
     return result
 
index bb1aeac6b4d12ae9edd1b8e84f275e464084bc2f..2fe10828d387deca22e600df5cafb5100d24d52d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -145,6 +145,9 @@ Core and Builtins
 Library
 -------
 
+- Issue 5021:  doctest.testfile() did not create __name__ and
+  collections.namedtuple() relied on __name__ being defined.
+
 - Backport importlib from Python 3.1. Only the import_module() function has
   been backported to help facilitate transitions from 2.7 to 3.1.