diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2007-07-23 13:41:45 +0000 |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2007-07-23 13:41:45 +0000 |
commit | ae21fc6d1fa52d6c26cca797cf1f88cd45f2f143 (patch) | |
tree | dfd7715d7840307353631b43e280a41ccc901029 /Lib/runpy.py | |
parent | f17a2e4f874a7f3e21a442c5adbbe600de0718f5 (diff) | |
download | cpython-git-ae21fc6d1fa52d6c26cca797cf1f88cd45f2f143.tar.gz |
Correctly cleanup sys.modules after executing runpy relative import
tests
Restore Python 2.4 ImportError when attempting to execute a package
(as imports cannot be guaranteed to work properly if you try it)
Diffstat (limited to 'Lib/runpy.py')
-rwxr-xr-x | Lib/runpy.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/runpy.py b/Lib/runpy.py index 8290dfea70..d2f18d37e3 100755 --- a/Lib/runpy.py +++ b/Lib/runpy.py @@ -84,10 +84,13 @@ def run_module(mod_name, init_globals=None, """ loader = get_loader(mod_name) if loader is None: - raise ImportError("No module named " + mod_name) + raise ImportError("No module named %s" % mod_name) + if loader.is_package(mod_name): + raise ImportError(("%s is a package and cannot " + + "be directly executed") % mod_name) code = loader.get_code(mod_name) if code is None: - raise ImportError("No code object available for " + mod_name) + raise ImportError("No code object available for %s" % mod_name) filename = _get_filename(loader, mod_name) if run_name is None: run_name = mod_name |