Author: Manuel Jacob <m...@manueljacob.de> Branch: py3.3 Changeset: r82333:01b8a2d215a6 Date: 2016-02-19 22:40 +0100 http://bitbucket.org/pypy/pypy/changeset/01b8a2d215a6/
Log: Backport patch from CPython Issue 26367. diff --git a/lib-python/3/importlib/_bootstrap.py b/lib-python/3/importlib/_bootstrap.py --- a/lib-python/3/importlib/_bootstrap.py +++ b/lib-python/3/importlib/_bootstrap.py @@ -1496,7 +1496,7 @@ raise TypeError("module name must be str, not {}".format(type(name))) if level < 0: raise ValueError('level must be >= 0') - if package: + if level > 0: if not isinstance(package, str): raise TypeError("__package__ not set to a string") elif package not in sys.modules: diff --git a/lib-python/3/test/test_importlib/import_/test_relative_imports.py b/lib-python/3/test/test_importlib/import_/test_relative_imports.py --- a/lib-python/3/test/test_importlib/import_/test_relative_imports.py +++ b/lib-python/3/test/test_importlib/import_/test_relative_imports.py @@ -208,6 +208,11 @@ with self.assertRaises(KeyError): import_util.import_('sys', level=1) + def test_relative_import_no_package_exists_absolute(self): + with self.assertRaises(SystemError): + self.__import__('sys', {'__package__': '', '__spec__': None}, + level=1) + def test_main(): from test.support import run_unittest _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit