From 0399598d2e1c9bbc74798fca6e39b427fb8d0562 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 6 Jun 2023 17:43:34 +0200 Subject: [PATCH 1/2] gh-105396: Deprecate PyImport_ImportModuleNoBlock() function Deprecate the PyImport_ImportModuleNoBlock() function which is just an alias to PyImport_ImportModule() since Python 3.3. --- Doc/c-api/import.rst | 3 +++ Doc/whatsnew/3.13.rst | 4 ++++ Include/import.h | 2 +- .../C API/2023-06-06-17-43-28.gh-issue-105396.FQJG5B.rst | 3 +++ Python/import.c | 6 ++++++ 5 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/C API/2023-06-06-17-43-28.gh-issue-105396.FQJG5B.rst diff --git a/Doc/c-api/import.rst b/Doc/c-api/import.rst index 79843ba521ab93..6db20237f3fdb0 100644 --- a/Doc/c-api/import.rst +++ b/Doc/c-api/import.rst @@ -38,6 +38,9 @@ Importing Modules to per-module locks for most purposes, so this function's special behaviour isn't needed anymore. + .. deprecated-removed:: 3.13 3.15 + Use :c:func:`PyImport_ImportModule` instead. + .. c:function:: PyObject* PyImport_ImportModuleEx(const char *name, PyObject *globals, PyObject *locals, PyObject *fromlist) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 35e6303c370e2f..d6869ecde81adb 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -393,6 +393,10 @@ Deprecated (Contributed by Victor Stinner in :gh:`105145`.) +* Deprecate the :c:func:`PyImport_ImportModuleNoBlock` function which is just + an alias to :c:func:`PyImport_ImportModule` since Python 3.3. + (Contributed by Victor Stinner in :gh:`105396`.) + Removed ------- diff --git a/Include/import.h b/Include/import.h index 5d5f3425b8e715..6c63744edb0634 100644 --- a/Include/import.h +++ b/Include/import.h @@ -46,7 +46,7 @@ PyAPI_FUNC(PyObject *) PyImport_AddModule( PyAPI_FUNC(PyObject *) PyImport_ImportModule( const char *name /* UTF-8 encoded string */ ); -PyAPI_FUNC(PyObject *) PyImport_ImportModuleNoBlock( +Py_DEPRECATED(3.13) PyAPI_FUNC(PyObject *) PyImport_ImportModuleNoBlock( const char *name /* UTF-8 encoded string */ ); PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevel( diff --git a/Misc/NEWS.d/next/C API/2023-06-06-17-43-28.gh-issue-105396.FQJG5B.rst b/Misc/NEWS.d/next/C API/2023-06-06-17-43-28.gh-issue-105396.FQJG5B.rst new file mode 100644 index 00000000000000..cf82f6202df17b --- /dev/null +++ b/Misc/NEWS.d/next/C API/2023-06-06-17-43-28.gh-issue-105396.FQJG5B.rst @@ -0,0 +1,3 @@ +Deprecate the :c:func:`PyImport_ImportModuleNoBlock` function which is just +an alias to :c:func:`PyImport_ImportModule` since Python 3.3. Patch by +Victor Stinner. diff --git a/Python/import.c b/Python/import.c index 7f04b1aa609f8a..71cce8e4f623dd 100644 --- a/Python/import.c +++ b/Python/import.c @@ -2439,6 +2439,12 @@ PyImport_ImportModule(const char *name) PyObject * PyImport_ImportModuleNoBlock(const char *name) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "PyImport_ImportModuleNoBlock() is deprecated and scheduled for " + "removal in Python 3.15. Use PyImport_ImportModule() instead.", 1)) + { + return NULL; + } return PyImport_ImportModule(name); } From 12b480d45cb677ae333b12495b8863d1ef5043c4 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 6 Jun 2023 20:03:40 +0200 Subject: [PATCH 2/2] Document scheduled removal --- Doc/whatsnew/3.13.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index d6869ecde81adb..58292e7247e228 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -395,6 +395,7 @@ Deprecated * Deprecate the :c:func:`PyImport_ImportModuleNoBlock` function which is just an alias to :c:func:`PyImport_ImportModule` since Python 3.3. + Scheduled for removal in Python 3.15. (Contributed by Victor Stinner in :gh:`105396`.) Removed