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?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4