summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2023-04-28 16:17:58 -0700
committerGitHub <noreply@github.com>2023-04-28 16:17:58 -0700
commite1f14643dc0e6024f8df9ae975c3b05912a3cb28 (patch)
tree00bb66f68cadb9457a2a9486873ecf13be0241d6 /Python
parent79b9db9295a5a1607a0b4b10a8b4b72567eaf1ef (diff)
downloadcpython-git-e1f14643dc0e6024f8df9ae975c3b05912a3cb28.tar.gz
gh-98040: Remove just the `imp` module (#98573)
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c8
-rwxr-xr-xPython/makeopcodetargets.py30
-rw-r--r--Python/pylifecycle.c7
-rw-r--r--Python/stdlib_module_names.h1
4 files changed, 19 insertions, 27 deletions
diff --git a/Python/import.c b/Python/import.c
index daec64ea4a..0bf107b28d 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -594,11 +594,11 @@ _PyImport_ClearModulesByIndex(PyInterpreterState *interp)
/*
It may help to have a big picture view of what happens
when an extension is loaded. This includes when it is imported
- for the first time or via imp.load_dynamic().
+ for the first time.
- Here's a summary, using imp.load_dynamic() as the starting point:
+ Here's a summary, using importlib._boostrap._load() as a starting point.
- 1. imp.load_dynamic() -> importlib._bootstrap._load()
+ 1. importlib._bootstrap._load()
2. _load(): acquire import lock
3. _load() -> importlib._bootstrap._load_unlocked()
4. _load_unlocked() -> importlib._bootstrap.module_from_spec()
@@ -3794,7 +3794,7 @@ _imp_source_hash_impl(PyObject *module, long key, Py_buffer *source)
PyDoc_STRVAR(doc_imp,
-"(Extremely) low-level import machinery bits as used by importlib and imp.");
+"(Extremely) low-level import machinery bits as used by importlib.");
static PyMethodDef imp_methods[] = {
_IMP_EXTENSION_SUFFIXES_METHODDEF
diff --git a/Python/makeopcodetargets.py b/Python/makeopcodetargets.py
index 5aa3180339..2b402ae0b6 100755
--- a/Python/makeopcodetargets.py
+++ b/Python/makeopcodetargets.py
@@ -7,24 +7,18 @@ import os
import sys
-try:
- from importlib.machinery import SourceFileLoader
-except ImportError:
- import imp
-
- def find_module(modname):
- """Finds and returns a module in the local dist/checkout.
- """
- modpath = os.path.join(
- os.path.dirname(os.path.dirname(__file__)), "Lib")
- return imp.load_module(modname, *imp.find_module(modname, [modpath]))
-else:
- def find_module(modname):
- """Finds and returns a module in the local dist/checkout.
- """
- modpath = os.path.join(
- os.path.dirname(os.path.dirname(__file__)), "Lib", modname + ".py")
- return SourceFileLoader(modname, modpath).load_module()
+# 2023-04-27(warsaw): Pre-Python 3.12, this would catch ImportErrors and try to
+# import imp, and then use imp.load_module(). The imp module was removed in
+# Python 3.12 (and long deprecated before that), and it's unclear under what
+# conditions this import will now fail, so the fallback was simply removed.
+from importlib.machinery import SourceFileLoader
+
+def find_module(modname):
+ """Finds and returns a module in the local dist/checkout.
+ """
+ modpath = os.path.join(
+ os.path.dirname(os.path.dirname(__file__)), "Lib", modname + ".py")
+ return SourceFileLoader(modname, modpath).load_module()
def write_contents(f):
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index d525fb1075..ba248d208e 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -2173,10 +2173,9 @@ add_main_module(PyInterpreterState *interp)
Py_DECREF(bimod);
}
- /* Main is a little special - imp.is_builtin("__main__") will return
- * False, but BuiltinImporter is still the most appropriate initial
- * setting for its __loader__ attribute. A more suitable value will
- * be set if __main__ gets further initialized later in the startup
+ /* Main is a little special - BuiltinImporter is the most appropriate
+ * initial setting for its __loader__ attribute. A more suitable value
+ * will be set if __main__ gets further initialized later in the startup
* process.
*/
loader = _PyDict_GetItemStringWithError(d, "__loader__");
diff --git a/Python/stdlib_module_names.h b/Python/stdlib_module_names.h
index e9f0061a59..27f42e5202 100644
--- a/Python/stdlib_module_names.h
+++ b/Python/stdlib_module_names.h
@@ -164,7 +164,6 @@ static const char* _Py_stdlib_module_names[] = {
"idlelib",
"imaplib",
"imghdr",
-"imp",
"importlib",
"inspect",
"io",