diff options
Diffstat (limited to 'Lib/runpy.py')
-rw-r--r-- | Lib/runpy.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/runpy.py b/Lib/runpy.py index 6d0954f147..1e0a2be4f0 100644 --- a/Lib/runpy.py +++ b/Lib/runpy.py @@ -13,7 +13,6 @@ importers when locating support scripts as well as when importing modules. import os import sys import importlib.machinery # importlib first so we can test #15386 via -m -import imp import types from pkgutil import read_code, get_loader, get_importer @@ -224,7 +223,12 @@ def run_path(path_name, init_globals=None, run_name=None): run_name = "<run_path>" pkg_name = run_name.rpartition(".")[0] importer = get_importer(path_name) - if isinstance(importer, (type(None), imp.NullImporter)): + # Trying to avoid importing imp so as to not consume the deprecation warning. + is_NullImporter = False + if type(importer).__module__ == 'imp': + if type(importer).__name__ == 'NullImporter': + is_NullImporter = True + if isinstance(importer, type(None)) or is_NullImporter: # Not a valid sys.path entry, so run the code directly # execfile() doesn't help as we want to allow compiled files code, mod_loader = _get_code_from_file(run_name, path_name) |