From: Thomas Heller Date: Thu, 30 Oct 2008 20:18:13 +0000 (+0000) Subject: Fixed a modulefinder crash on certain relative imports. X-Git-Tag: v2.7a1~2697 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fac5a450562c50a3b7121598da7f010a306e50f;p=thirdparty%2FPython%2Fcpython.git Fixed a modulefinder crash on certain relative imports. --- diff --git a/Lib/modulefinder.py b/Lib/modulefinder.py index ad6a644e1e6c..7f2bf8b15887 100644 --- a/Lib/modulefinder.py +++ b/Lib/modulefinder.py @@ -309,7 +309,10 @@ class ModuleFinder: def _add_badmodule(self, name, caller): if name not in self.badmodules: self.badmodules[name] = {} - self.badmodules[name][caller.__name__] = 1 + if caller: + self.badmodules[name][caller.__name__] = 1 + else: + self.badmodules[name]["-"] = 1 def _safe_import_hook(self, name, caller, fromlist, level=-1): # wrapper for self.import_hook() that won't raise ImportError diff --git a/Lib/test/test_modulefinder.py b/Lib/test/test_modulefinder.py index b62758a8b52d..9d7f76afdf7c 100644 --- a/Lib/test/test_modulefinder.py +++ b/Lib/test/test_modulefinder.py @@ -190,6 +190,19 @@ a/b/c/e.py a/b/c/f.py """] +relative_import_test_3 = [ + "a.module", + ["a", "a.module"], + ["a.bar"], + [], + """\ +a/__init__.py + def foo(): pass +a/module.py + from . import foo + from . import bar +"""] + def open_file(path): ##print "#", os.path.abspath(path) dirname = os.path.dirname(path) @@ -256,6 +269,9 @@ class ModuleFinderTest(unittest.TestCase): def test_relative_imports_2(self): self._do_test(relative_import_test_2) + def test_relative_imports_3(self): + self._do_test(relative_import_test_3) + def test_main(): distutils.log.set_threshold(distutils.log.WARN) test_support.run_unittest(ModuleFinderTest) diff --git a/Misc/NEWS b/Misc/NEWS index ae89094241e6..d6f3cae8d76f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -30,6 +30,8 @@ Core and Builtins Library ------- +- Fixed a modulefinder crash on certain relative imports. + - Issue #4150: Pdb's "up" command now works for generator frames in post-mortem debugging.