diff options
author | Victor Stinner <vstinner@python.org> | 2021-03-23 18:22:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-23 18:22:57 (GMT) |
commit | bd9154a495434464283f74b660160f89930cd791 (patch) | |
tree | fd4a7ca67c4f063641caa1f56511ce149eb2d8c3 /Lib/runpy.py | |
parent | d72e8d487553c103bf2742e229f8266b515fd951 (diff) | |
download | cpython-bd9154a495434464283f74b660160f89930cd791.zip cpython-bd9154a495434464283f74b660160f89930cd791.tar.gz cpython-bd9154a495434464283f74b660160f89930cd791.tar.bz2 |
bpo-41718: runpy now imports pkgutil in functions (GH-24996)
Reduce the number of modules imported by "python3 -m module".
The runpy module no longer imports at startup (in the module body),
but only in functions using it: _get_code_from_file() and run_path().
Diffstat (limited to 'Lib/runpy.py')
-rw-r--r-- | Lib/runpy.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Lib/runpy.py b/Lib/runpy.py index 7e1e1ac..caba121 100644 --- a/Lib/runpy.py +++ b/Lib/runpy.py @@ -16,7 +16,6 @@ import importlib.util import io import types import os -from pkgutil import read_code, get_importer __all__ = [ "run_module", "run_path", @@ -233,6 +232,7 @@ def _get_main_module_details(error=ImportError): def _get_code_from_file(run_name, fname): # Check for a compiled file first + from pkgutil import read_code decoded_path = os.path.abspath(os.fsdecode(fname)) with io.open_code(decoded_path) as f: code = read_code(f) @@ -255,6 +255,7 @@ def run_path(path_name, init_globals=None, run_name=None): if run_name is None: run_name = "<run_path>" pkg_name = run_name.rpartition(".")[0] + from pkgutil import get_importer importer = get_importer(path_name) # Trying to avoid importing imp so as to not consume the deprecation warning. is_NullImporter = False |