bpo-40417: Fix deprecation warning in PyImport_ReloadModule (GH-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
This commit is contained in:
parent
7ba08ff7b4
commit
f40bd466bf
|
@ -0,0 +1 @@
|
||||||
|
Fix imp module deprecation warning when PyImport_ReloadModule is called. Patch by Robert Rouhani.
|
|
@ -1978,23 +1978,23 @@ PyImport_ImportModuleLevel(const char *name, PyObject *globals, PyObject *locals
|
||||||
PyObject *
|
PyObject *
|
||||||
PyImport_ReloadModule(PyObject *m)
|
PyImport_ReloadModule(PyObject *m)
|
||||||
{
|
{
|
||||||
_Py_IDENTIFIER(imp);
|
_Py_IDENTIFIER(importlib);
|
||||||
_Py_IDENTIFIER(reload);
|
_Py_IDENTIFIER(reload);
|
||||||
PyObject *reloaded_module = NULL;
|
PyObject *reloaded_module = NULL;
|
||||||
PyObject *imp = _PyImport_GetModuleId(&PyId_imp);
|
PyObject *importlib = _PyImport_GetModuleId(&PyId_importlib);
|
||||||
if (imp == NULL) {
|
if (importlib == NULL) {
|
||||||
if (PyErr_Occurred()) {
|
if (PyErr_Occurred()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
imp = PyImport_ImportModule("imp");
|
importlib = PyImport_ImportModule("importlib");
|
||||||
if (imp == NULL) {
|
if (importlib == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reloaded_module = _PyObject_CallMethodIdOneArg(imp, &PyId_reload, m);
|
reloaded_module = _PyObject_CallMethodIdOneArg(importlib, &PyId_reload, m);
|
||||||
Py_DECREF(imp);
|
Py_DECREF(importlib);
|
||||||
return reloaded_module;
|
return reloaded_module;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue