[Python-checkins] [3.7] bpo-40417: Fix deprecation warning in PyImport_ReloadModule (GH-19750) (GH-19935)

Robert Rouhani webhook-mailer at python.org
Tue May 5 20:49:37 EDT 2020


https://github.com/python/cpython/commit/d64fd617e02346ecbcba9559f227936e08e89602
commit: d64fd617e02346ecbcba9559f227936e08e89602
branch: 3.7
author: Robert Rouhani <robert.rouhani at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-05-05T17:49:29-07:00
summary:

[3.7] bpo-40417: Fix deprecation warning in PyImport_ReloadModule (GH-19750) (GH-19935)



Use importlib instead of imp.

Automerge-Triggered-By: @brettcannon.
(cherry picked from commit f40bd46)

Co-authored-by: Robert Rouhani robert.rouhani at gmail.com

files:
A Misc/NEWS.d/next/Core and Builtins/2020-05-01-19-04-52.bpo-40417.Sti2lJ.rst
M Python/import.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-05-01-19-04-52.bpo-40417.Sti2lJ.rst b/Misc/NEWS.d/next/Core and Builtins/2020-05-01-19-04-52.bpo-40417.Sti2lJ.rst
new file mode 100644
index 0000000000000..932e853a8933d
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2020-05-01-19-04-52.bpo-40417.Sti2lJ.rst	
@@ -0,0 +1 @@
+Fix imp module deprecation warning when PyImport_ReloadModule is called. Patch by Robert Rouhani.
diff --git a/Python/import.c b/Python/import.c
index edc59249622b1..6d014cf5b008f 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1858,23 +1858,23 @@ PyImport_ImportModuleLevel(const char *name, PyObject *globals, PyObject *locals
 PyObject *
 PyImport_ReloadModule(PyObject *m)
 {
-    _Py_IDENTIFIER(imp);
+    _Py_IDENTIFIER(importlib);
     _Py_IDENTIFIER(reload);
     PyObject *reloaded_module = NULL;
-    PyObject *imp = _PyImport_GetModuleId(&PyId_imp);
-    if (imp == NULL) {
+    PyObject *importlib = _PyImport_GetModuleId(&PyId_importlib);
+    if (importlib == NULL) {
         if (PyErr_Occurred()) {
             return NULL;
         }
 
-        imp = PyImport_ImportModule("imp");
-        if (imp == NULL) {
+        importlib = PyImport_ImportModule("importlib");
+        if (importlib == NULL) {
             return NULL;
         }
     }
 
-    reloaded_module = _PyObject_CallMethodIdObjArgs(imp, &PyId_reload, m, NULL);
-    Py_DECREF(imp);
+    reloaded_module = _PyObject_CallMethodIdObjArgs(importlib, &PyId_reload, m, NULL);
+    Py_DECREF(importlib);
     return reloaded_module;
 }
 



More information about the Python-checkins mailing list