From ecf252abac71be8bcf7c4daa8f3a8ca6acd15b0c Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 27 Jan 2009 10:03:04 +0000 Subject: [PATCH] Issue 5021: doctest.testfile should set __name__ --- Lib/collections.py | 2 +- Misc/NEWS | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/collections.py b/Lib/collections.py index effae7dd8d..0fddb97f9f 100644 --- a/Lib/collections.py +++ b/Lib/collections.py @@ -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 diff --git a/Misc/NEWS b/Misc/NEWS index bb1aeac6b4..2fe10828d3 100644 --- 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. -- 2.50.1