From 5976d975f8f16ebc7f5d218dfdcaf28411a4c0d2 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Sat, 12 Jun 2010 00:38:29 +0000 Subject: When dealing with __import__ for detecting a global state change made by a test, make sure to check if __builtins__ is a dict or not. Discovered when running importlib.test.regrtest. --- Lib/test/regrtest.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 34b743e..8b46f6e 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -859,9 +859,15 @@ class saved_test_environment: sys.path_hooks[:] = saved_hooks[2] def get___import__(self): - return __builtins__.__import__ + if isinstance(__builtins__, dict): + return __builtins__['__import__'] + else: + return __builtins__.__import__ def restore___import__(self, import_): - __builtins__.__import__ = import_ + if isinstance(__builtins__, dict): + __builtins__['__import__'] = import_ + else: + __builtins__.__import__ = import_ def get_warnings_filters(self): return id(warnings.filters), warnings.filters, warnings.filters[:] -- cgit v0.12