diff options
| author | Brett Cannon <brett@python.org> | 2012-04-03 00:33:56 (GMT) |
|---|---|---|
| committer | Brett Cannon <brett@python.org> | 2012-04-03 00:33:56 (GMT) |
| commit | 927d87470a0b6f7b0ca3f3a1b39fd3bdc0ec919a (patch) | |
| tree | 14751257ed51a52e66dd9dcf85eb17ffb2fc77cf /Lib/importlib/_bootstrap.py | |
| parent | 368b4b74050290a77f32cafa8c7fac3542bc6308 (diff) | |
| download | cpython-927d87470a0b6f7b0ca3f3a1b39fd3bdc0ec919a.zip cpython-927d87470a0b6f7b0ca3f3a1b39fd3bdc0ec919a.tar.gz cpython-927d87470a0b6f7b0ca3f3a1b39fd3bdc0ec919a.tar.bz2 | |
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.
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
| -rw-r--r-- | Lib/importlib/_bootstrap.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index e0f86fc..d81e949 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -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: |
