summaryrefslogtreecommitdiffstats
path: root/Lib/runpy.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2013-06-16 17:13:40 (GMT)
committerBrett Cannon <brett@python.org>2013-06-16 17:13:40 (GMT)
commite4f41deccf94ccc798b1eb1f44657ade66669a60 (patch)
tree8f47ca73224c628f4afcebb9dd989cac73d0f8d1 /Lib/runpy.py
parent39295e7a55d03b9ef31c0d0dd27d129b1ad5a695 (diff)
downloadcpython-e4f41deccf94ccc798b1eb1f44657ade66669a60.zip
cpython-e4f41deccf94ccc798b1eb1f44657ade66669a60.tar.gz
cpython-e4f41deccf94ccc798b1eb1f44657ade66669a60.tar.bz2
Issue #17177: The imp module is pending deprecation.
To make sure there is no issue with code that is both Python 2 and 3 compatible, there are no plans to remove the module any sooner than Python 4 (unless the community moves to Python 3 solidly before then).
Diffstat (limited to 'Lib/runpy.py')
-rw-r--r--Lib/runpy.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/runpy.py b/Lib/runpy.py
index 6d0954f..1e0a2be 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)