bpo-30876: Relative import from unloaded package now reimports the package (#2639)

instead of failing with SystemError.

Relative import from non-package now fails with ImportError rather than
SystemError.
This commit is contained in:
Serhiy Storchaka 2017-07-12 06:50:03 +03:00 committed by GitHub
parent 6d13b22e3a
commit 8a9cd20edc
8 changed files with 390 additions and 388 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')