If a module injects something into sys.modules as a side-effect of

importation, then respect that injection.

Discovered thanks to Lib/xml/parsers/expat.py injecting
xml.parsers.expat.errors and etree now importing that directly as a
module.
This commit is contained in:
Brett Cannon 2012-04-02 20:33:56 -04:00
parent 368b4b7405
commit 927d87470a
2 changed files with 16 additions and 0 deletions

View file

@ -927,6 +927,9 @@ def _find_and_load(name, import_):
if parent:
if parent not in sys.modules:
import_(parent)
# Crazy side-effects!
if name in sys.modules:
return sys.modules[name]
# Backwards-compatibility; be nicer to skip the dict lookup.
parent_module = sys.modules[parent]
try: