I thought that in order to block a module from being imported, one would need to assign None to the corresponding entry in sys.modules. However, it looks like the code in test.support uses 0 instead of None:
def _save_and_block_module(name, orig_modules): """Helper function to save and block a module in sys.modules Return value is True if the module was in sys.modules and False otherwise.""" saved = True try: orig_modules[name] = sys.modules[name] except KeyError: saved = False sys.modules[name] = 0 # <--- I would expect None here return saved In my experiments, 0 is not equivalent to None: >>> import sys, time >>> sys.modules['time'] = 0 >>> __import__('time') 0 >>> sys.modules['time'] = None >>> __import__('time') Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named time Am I missing something? _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com