From 8031bbec4a50d98b53815d77e4c5fe8549ab97eb Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 31 Aug 2001 17:46:35 +0000 Subject: [PATCH] Allow for the possibility that globals['__name__'] does not exist; substitute "" for the module name in that case. This actually occurred when running test_descr.py with -Dwarn. --- Lib/warnings.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/warnings.py b/Lib/warnings.py index ea68e4c8db2..5bb00c19758 100644 --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -24,7 +24,10 @@ def warn(message, category=None, stacklevel=1): else: globals = caller.f_globals lineno = caller.f_lineno - module = globals['__name__'] + if globals.has_key('__name__'): + module = globals['__name__'] + else: + module = "" filename = globals.get('__file__') if filename: fnl = filename.lower()