[3.6] bpo-31642: Restore blocking "from" import by setting None in sys.modules. (GH-3834). (#3923)

(cherry picked from commit f07e2b64df)
This commit is contained in:
Serhiy Storchaka 2017-10-08 12:51:55 +03:00 committed by GitHub
parent d13a4e5067
commit 6f059ab80a
4 changed files with 259 additions and 239 deletions

View file

@ -1019,7 +1019,8 @@ def _handle_fromlist(module, fromlist, import_):
# Backwards-compatibility dictates we ignore failed
# imports triggered by fromlist for modules that don't
# exist.
if exc.name == from_name:
if (exc.name == from_name and
sys.modules.get(from_name, _NEEDS_LOADING) is not None):
continue
raise
return module