diff --git a/Misc/NEWS.d/next/C API/2021-12-11-08-41-36.bpo-45855.Lq2_gR.rst b/Misc/NEWS.d/next/C API/2021-12-11-08-41-36.bpo-45855.Lq2_gR.rst new file mode 100644 index 00000000000000..03258df00420f0 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2021-12-11-08-41-36.bpo-45855.Lq2_gR.rst @@ -0,0 +1 @@ +Replaced deprecated usage of :c:func:`PyImport_ImportModuleNoBlock` with :c:func:`PyImport_ImportModule` in stdlib modules. Patch by Kumar Aditya. \ No newline at end of file diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c index 0f7789a973e8f2..01d703745bc606 100644 --- a/Modules/_ctypes/callbacks.c +++ b/Modules/_ctypes/callbacks.c @@ -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 */ @@ -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 diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index 7ebad692c2381d..bf742dacf01105 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -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); diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 67441eba28f7f6..fda8401b84cd15 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -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; @@ -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); @@ -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; } @@ -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; } diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 2d95efebb1033f..b3a5757a8221dd 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -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); diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index bc891e8af3c0b2..2013f16ed440ee 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -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); diff --git a/Modules/timemodule.c b/Modules/timemodule.c index bb713908eb1e49..dd81d352fd713d 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -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; @@ -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; } diff --git a/Objects/capsule.c b/Objects/capsule.c index 800a6c4b25c6df..9c9dcf33f9f757 100644 --- a/Objects/capsule.c +++ b/Objects/capsule.c @@ -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) { diff --git a/Parser/pegen.c b/Parser/pegen.c index 4158a81fd52f77..870085e7285e3b 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -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; diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 6358cdf654e185..9dbd103995e4df 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -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; diff --git a/Python/codecs.c b/Python/codecs.c index b7c8db7e8b6189..343b6e2d03396e 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -1527,7 +1527,7 @@ static int _PyCodecRegistry_Init(void) } } - mod = PyImport_ImportModuleNoBlock("encodings"); + mod = PyImport_ImportModule("encodings"); if (mod == NULL) { return -1; } diff --git a/Python/traceback.c b/Python/traceback.c index b0ff5e9a6b0757..4d6cbaae8da6cd 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -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");