Skip to content

Commit 78bd252

Browse files
committed
[3.8] bpo-40417: Fix deprecation warning in PyImport_ReloadModule (pythonGH-19750)
I can add another commit with the new test case I wrote to verify that the warning was being printed before my change, stopped printing after my change, and that the function does not return null after my change. Automerge-Triggered-By: @brettcannon. (cherry picked from commit f40bd46) Co-authored-by: Robert Rouhani <[email protected]>
1 parent efc782d commit 78bd252

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix imp module deprecation warning when PyImport_ReloadModule is called. Patch by Robert Rouhani.

Python/import.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,23 +1908,23 @@ PyImport_ImportModuleLevel(const char *name, PyObject *globals, PyObject *locals
19081908
PyObject *
19091909
PyImport_ReloadModule(PyObject *m)
19101910
{
1911-
_Py_IDENTIFIER(imp);
1911+
_Py_IDENTIFIER(importlib);
19121912
_Py_IDENTIFIER(reload);
19131913
PyObject *reloaded_module = NULL;
1914-
PyObject *imp = _PyImport_GetModuleId(&PyId_imp);
1915-
if (imp == NULL) {
1914+
PyObject *importlib = _PyImport_GetModuleId(&PyId_importlib);
1915+
if (importlib == NULL) {
19161916
if (PyErr_Occurred()) {
19171917
return NULL;
19181918
}
19191919

1920-
imp = PyImport_ImportModule("imp");
1921-
if (imp == NULL) {
1920+
importlib = PyImport_ImportModule("importlib");
1921+
if (importlib == NULL) {
19221922
return NULL;
19231923
}
19241924
}
19251925

1926-
reloaded_module = _PyObject_CallMethodIdObjArgs(imp, &PyId_reload, m, NULL);
1927-
Py_DECREF(imp);
1926+
reloaded_module = _PyObject_CallMethodIdObjArgs(importlib, &PyId_reload, m, NULL);
1927+
Py_DECREF(importlib);
19281928
return reloaded_module;
19291929
}
19301930

0 commit comments

Comments
 (0)