[3.6] bpo-30876: Relative import from unloaded package now reimports the package (GH-2639) (#2676)

instead of failing with SystemError.

Relative import from non-package now fails with ImportError rather than
SystemError.
(cherry picked from commit 8a9cd20edc)
This commit is contained in:
Serhiy Storchaka 2017-07-16 07:44:25 +03:00 committed by GitHub
parent 65de1f3672
commit 28343e3392
8 changed files with 381 additions and 379 deletions

View file

@ -919,10 +919,6 @@ def _sanity_check(name, package, level):
elif not package:
raise ImportError('attempted relative import with no known parent '
'package')
elif package not in sys.modules:
msg = ('Parent module {!r} not loaded, cannot perform relative '
'import')
raise SystemError(msg.format(package))
if not name and level == 0:
raise ValueError('Empty module name')