[Python-checkins] bpo-45855: Replaced deprecated `PyImport_ImportModuleNoBlock` with PyImport_ImportModule (GH-30046)

asvetlov webhook-mailer at python.org
Sun Dec 12 03:45:28 EST 2021


https://github.com/python/cpython/commit/41026c3155012d6ea50e01205c163b6739c675b8
commit: 41026c3155012d6ea50e01205c163b6739c675b8
branch: main
author: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>
committer: asvetlov <andrew.svetlov at gmail.com>
date: 2021-12-12T10:45:20+02:00
summary:

bpo-45855: Replaced deprecated `PyImport_ImportModuleNoBlock` with PyImport_ImportModule (GH-30046)

files:
A Misc/NEWS.d/next/C API/2021-12-11-08-41-36.bpo-45855.Lq2_gR.rst
M Modules/_ctypes/callbacks.c
M Modules/_cursesmodule.c
M Modules/_datetimemodule.c
M Modules/posixmodule.c
M Modules/signalmodule.c
M Modules/timemodule.c
M Objects/capsule.c
M Parser/pegen.c
M Parser/tokenizer.c
M Python/codecs.c
M Python/traceback.c

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 0000000000000..03258df00420f
--- /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 0f7789a973e8f..01d703745bc60 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 7ebad692c2381..bf742dacf0110 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 67441eba28f7f..fda8401b84cd1 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 2d95efebb1033..b3a5757a8221d 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 bc891e8af3c0b..2013f16ed440e 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 bb713908eb1e4..dd81d352fd713 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 800a6c4b25c6d..9c9dcf33f9f75 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 4158a81fd52f7..870085e7285e3 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 a560572ac6197..5e35d6fa621b1 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 b7c8db7e8b618..343b6e2d03396 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 b0ff5e9a6b075..4d6cbaae8da6c 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");



More information about the Python-checkins mailing list