New submission from Calvin Spealman <ironfro...@gmail.com>: I came across this behavior when it was related to the shadowing of a small typo bug and took me forever to find. In my case, the original error was shadowed in a way that is unrelated to this bug, but lead to the module being imported twice (because it was removed when it failed the first time) and then the second import caused a completely unexpected error, because the state of the submodules conflicted with the import-time logic of the top-level package.
I think when a module fails to load, all of its sub-modules should be removed from sys.modules, not just itself. calvin@willow-delta:/tmp$ mkdir foo/ calvin@willow-delta:/tmp$ cat >> foo/__init__.py import foo.bar 1/0 calvin@willow-delta:/tmp$ cat >> foo/bar.py name = "bar" calvin@willow-delta:/tmp$ python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import foo Traceback (most recent call last): File "<stdin>", line 1, in <module> File "foo/__init__.py", line 2, in <module> 1/0 ZeroDivisionError: integer division or modulo by zero >>> import sys >>> sys.modules['foo.bar'] <module 'foo.bar' from 'foo/bar.py'> >>> ---------- components: Interpreter Core messages: 140298 nosy: Calvin.Spealman priority: normal severity: normal status: open title: Failed imports clean up module, but not sub modules type: behavior _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue12554> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com