diff -r eafff38a56cc Lib/modulefinder.py --- a/Lib/modulefinder.py Fri May 10 05:22:14 2013 +0300 +++ b/Lib/modulefinder.py Sun May 12 22:16:12 2013 +0200 @@ -282,7 +282,11 @@ self.msgout(2, "load_module ->", m) return m if type == imp.PY_SOURCE: - co = compile(fp.read()+'\n', pathname, 'exec') + try: + co = compile(fp.read()+'\n', pathname, 'exec') + except SyntaxError: + self.msgout(2, "raise ImportError: Syntax error", pathname) + raise ImportError("Syntax error in %s" % pathname) elif type == imp.PY_COMPILED: if fp.read(4) != imp.get_magic(): self.msgout(2, "raise ImportError: Bad magic number", pathname) diff -r eafff38a56cc Lib/test/test_modulefinder.py --- a/Lib/test/test_modulefinder.py Fri May 10 05:22:14 2013 +0300 +++ b/Lib/test/test_modulefinder.py Sun May 12 22:16:12 2013 +0200 @@ -208,6 +208,19 @@ from . import * """] +import_with_syntax_error_test = [ + "a.module", + ["a", "a.module", "b"], + ["b.module"], [], + """\ +a/__init__.py +a/module.py + import b.module +b/__init__.py +b/module.py + : # Syntax error +"""] + def open_file(path): dirname = os.path.dirname(path) @@ -288,6 +301,9 @@ def test_relative_imports_4(self): self._do_test(relative_import_test_4) + def test_import_with_syntax_error(self): + self._do_test(import_with_syntax_error_test) + def test_main(): support.run_unittest(ModuleFinderTest) diff -r eafff38a56cc Misc/ACKS --- a/Misc/ACKS Fri May 10 05:22:14 2013 +0300 +++ b/Misc/ACKS Sun May 12 22:16:12 2013 +0200 @@ -447,6 +447,7 @@ Chris Gonnerman Shelley Gooch David Goodger +Jan Gosmann Hans de Graaff Nathaniel Gray Eddy De Greef