summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-04-03 04:35:44 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-04-03 04:35:44 (GMT)
commitb845decc22c8082b77e153d6c6b67de251bfb049 (patch)
treed015a6fb85e444e81831c14cfe16e64ac445b06e /Lib/importlib
parent0a9a6363025ba16b1c2041a05e6f33ee408b1bda (diff)
parent5ceef131d42852fc1db1de0dd565196c4e29a397 (diff)
downloadcpython-b845decc22c8082b77e153d6c6b67de251bfb049.zip
cpython-b845decc22c8082b77e153d6c6b67de251bfb049.tar.gz
cpython-b845decc22c8082b77e153d6c6b67de251bfb049.tar.bz2
merge heads
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap.py3
-rw-r--r--Lib/importlib/test/import_/test_packages.py13
2 files changed, 16 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:
diff --git a/Lib/importlib/test/import_/test_packages.py b/Lib/importlib/test/import_/test_packages.py
index faadc32..9590d5f 100644
--- a/Lib/importlib/test/import_/test_packages.py
+++ b/Lib/importlib/test/import_/test_packages.py
@@ -27,6 +27,19 @@ class ParentModuleTests(unittest.TestCase):
with self.assertRaises(ImportError):
import_util.import_('sys.no_submodules_here')
+ def test_module_not_package_but_side_effects(self):
+ # If a module injects something into sys.modules as a side-effect, then
+ # pick up on that fact.
+ name = 'mod'
+ subname = name + '.b'
+ def module_injection():
+ sys.modules[subname] = 'total bunk'
+ mock_modules = util.mock_modules('mod',
+ module_code={'mod': module_injection})
+ with mock_modules as mock:
+ with util.import_state(meta_path=[mock]):
+ submodule = import_util.import_(subname)
+
def test_main():
from test.support import run_unittest