Skip to content

Commit d64fd61

Browse files
authored
[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 [email protected]
1 parent 8ddf915 commit d64fd61

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed
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

+7-7
Original file line numberDiff line numberDiff line change
@@ -1858,23 +1858,23 @@ PyImport_ImportModuleLevel(const char *name, PyObject *globals, PyObject *locals
18581858
PyObject *
18591859
PyImport_ReloadModule(PyObject *m)
18601860
{
1861-
_Py_IDENTIFIER(imp);
1861+
_Py_IDENTIFIER(importlib);
18621862
_Py_IDENTIFIER(reload);
18631863
PyObject *reloaded_module = NULL;
1864-
PyObject *imp = _PyImport_GetModuleId(&PyId_imp);
1865-
if (imp == NULL) {
1864+
PyObject *importlib = _PyImport_GetModuleId(&PyId_importlib);
1865+
if (importlib == NULL) {
18661866
if (PyErr_Occurred()) {
18671867
return NULL;
18681868
}
18691869

1870-
imp = PyImport_ImportModule("imp");
1871-
if (imp == NULL) {
1870+
importlib = PyImport_ImportModule("importlib");
1871+
if (importlib == NULL) {
18721872
return NULL;
18731873
}
18741874
}
18751875

1876-
reloaded_module = _PyObject_CallMethodIdObjArgs(imp, &PyId_reload, m, NULL);
1877-
Py_DECREF(imp);
1876+
reloaded_module = _PyObject_CallMethodIdObjArgs(importlib, &PyId_reload, m, NULL);
1877+
Py_DECREF(importlib);
18781878
return reloaded_module;
18791879
}
18801880

0 commit comments

Comments
 (0)