mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
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).
This commit is contained in:
parent
39295e7a55
commit
e4f41deccf
15 changed files with 103 additions and 85 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue