Skip to content

bpo-45855: Replaced deprecated PyImport_ImportModuleNoBlock with PyIm… #30046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replaced deprecated usage of :c:func:`PyImport_ImportModuleNoBlock` with :c:func:`PyImport_ImportModule` in stdlib modules. Patch by Kumar Aditya.
4 changes: 2 additions & 2 deletions Modules/_ctypes/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
if (context == NULL)
context = PyUnicode_InternFromString("_ctypes.DllGetClassObject");

mod = PyImport_ImportModuleNoBlock("ctypes");
mod = PyImport_ImportModule("ctypes");
if (!mod) {
PyErr_WriteUnraisable(context ? context : Py_None);
/* There has been a warning before about this already */
Expand Down Expand Up @@ -563,7 +563,7 @@ long Call_CanUnloadNow(void)
if (context == NULL)
context = PyUnicode_InternFromString("_ctypes.DllCanUnloadNow");

mod = PyImport_ImportModuleNoBlock("ctypes");
mod = PyImport_ImportModule("ctypes");
if (!mod) {
/* OutputDebugString("Could not import ctypes"); */
/* We assume that this error can only occur when shutting
Expand Down
2 changes: 1 addition & 1 deletion Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3959,7 +3959,7 @@ static int
update_lines_cols(void)
{
PyObject *o;
PyObject *m = PyImport_ImportModuleNoBlock("curses");
PyObject *m = PyImport_ImportModule("curses");
_Py_IDENTIFIER(LINES);
_Py_IDENTIFIER(COLS);

Expand Down
8 changes: 4 additions & 4 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
goto Done;
{
PyObject *format;
PyObject *time = PyImport_ImportModuleNoBlock("time");
PyObject *time = PyImport_ImportModule("time");

if (time == NULL)
goto Done;
Expand Down Expand Up @@ -1655,7 +1655,7 @@ static PyObject *
time_time(void)
{
PyObject *result = NULL;
PyObject *time = PyImport_ImportModuleNoBlock("time");
PyObject *time = PyImport_ImportModule("time");

if (time != NULL) {
_Py_IDENTIFIER(time);
Expand All @@ -1678,7 +1678,7 @@ build_struct_time(int y, int m, int d, int hh, int mm, int ss, int dstflag)
PyObject *args;


time = PyImport_ImportModuleNoBlock("time");
time = PyImport_ImportModule("time");
if (time == NULL) {
return NULL;
}
Expand Down Expand Up @@ -5161,7 +5161,7 @@ datetime_strptime(PyObject *cls, PyObject *args)
return NULL;

if (module == NULL) {
module = PyImport_ImportModuleNoBlock("_strptime");
module = PyImport_ImportModule("_strptime");
if (module == NULL)
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -8219,7 +8219,7 @@ wait_helper(PyObject *module, pid_t pid, int status, struct rusage *ru)
memset(ru, 0, sizeof(*ru));
}

PyObject *m = PyImport_ImportModuleNoBlock("resource");
PyObject *m = PyImport_ImportModule("resource");
if (m == NULL)
return NULL;
struct_rusage = PyObject_GetAttr(m, get_posix_state(module)->struct_rusage);
Expand Down
2 changes: 1 addition & 1 deletion Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ signal_set_wakeup_fd(PyObject *self, PyObject *args, PyObject *kwds)
is_socket = 0;
if (sockfd != INVALID_FD) {
/* Import the _socket module to call WSAStartup() */
mod = PyImport_ImportModuleNoBlock("_socket");
mod = PyImport_ImportModule("_socket");
if (mod == NULL)
return NULL;
Py_DECREF(mod);
Expand Down
4 changes: 2 additions & 2 deletions Modules/timemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ time_strptime(PyObject *self, PyObject *args)
PyObject *module, *func, *result;
_Py_IDENTIFIER(_strptime_time);

module = PyImport_ImportModuleNoBlock("_strptime");
module = PyImport_ImportModule("_strptime");
if (!module)
return NULL;

Expand Down Expand Up @@ -1075,7 +1075,7 @@ time_tzset(PyObject *self, PyObject *unused)
{
PyObject* m;

m = PyImport_ImportModuleNoBlock("time");
m = PyImport_ImportModule("time");
if (m == NULL) {
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion Objects/capsule.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ PyCapsule_Import(const char *name, int no_block)

if (object == NULL) {
if (no_block) {
object = PyImport_ImportModuleNoBlock(trace);
object = PyImport_ImportModule(trace);
} else {
object = PyImport_ImportModule(trace);
if (!object) {
Expand Down
2 changes: 1 addition & 1 deletion Parser/pegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ init_normalization(Parser *p)
if (p->normalize) {
return 1;
}
PyObject *m = PyImport_ImportModuleNoBlock("unicodedata");
PyObject *m = PyImport_ImportModule("unicodedata");
if (!m)
{
return 0;
Expand Down
2 changes: 1 addition & 1 deletion Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ fp_setreadl(struct tok_state *tok, const char* enc)
return 0;
}

io = PyImport_ImportModuleNoBlock("io");
io = PyImport_ImportModule("io");
if (io == NULL)
return 0;

Expand Down
2 changes: 1 addition & 1 deletion Python/codecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ static int _PyCodecRegistry_Init(void)
}
}

mod = PyImport_ImportModuleNoBlock("encodings");
mod = PyImport_ImportModule("encodings");
if (mod == NULL) {
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion Python/traceback.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int
}
}

io = PyImport_ImportModuleNoBlock("io");
io = PyImport_ImportModule("io");
if (io == NULL)
return -1;
binary = _PyObject_CallMethodId(io, &PyId_open, "Os", filename, "rb");
Expand Down