mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
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)
This commit is contained in:
parent
f17a2e4f87
commit
ae21fc6d1f
2 changed files with 11 additions and 8 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue