]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-133644: remove deprecated `PyImport_ImportModuleNoBlock` (#133655)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Thu, 8 May 2025 13:08:43 +0000 (15:08 +0200)
committerGitHub <noreply@github.com>
Thu, 8 May 2025 13:08:43 +0000 (13:08 +0000)
17 files changed:
Doc/c-api/import.rst
Doc/data/refcounts.dat
Doc/data/stable_abi.dat
Doc/deprecations/c-api-pending-removal-in-3.15.rst
Doc/whatsnew/2.6.rst
Doc/whatsnew/3.0.rst
Doc/whatsnew/3.13.rst
Doc/whatsnew/3.15.rst
Doc/whatsnew/3.3.rst
Include/import.h
Lib/test/test_capi/test_import.py
Misc/NEWS.d/3.11.0a4.rst
Misc/NEWS.d/3.13.0a1.rst
Misc/NEWS.d/next/C_API/2025-05-08-12-25-47.gh-issue-133644.Yb86Rm.rst [new file with mode: 0644]
Misc/stable_abi.toml
Modules/_testlimitedcapi/import.c
Python/import.c

index 1cab3ce3061ec90bae07fb336920413954aff408..8eabc0406b11ce58cbc9f8c88c0163a93447dbf8 100644 (file)
@@ -16,19 +16,6 @@ Importing Modules
    This is a wrapper around :c:func:`PyImport_Import()` which takes a
    :c:expr:`const char *` as an argument instead of a :c:expr:`PyObject *`.
 
-.. c:function:: PyObject* PyImport_ImportModuleNoBlock(const char *name)
-
-   This function is a deprecated alias of :c:func:`PyImport_ImportModule`.
-
-   .. versionchanged:: 3.3
-      This function used to fail immediately when the import lock was held
-      by another thread.  In Python 3.3 though, the locking scheme switched
-      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)
 
index ca99b9e6d371418e20d5a67a6cd68414e2721a2b..14990bee6e4f230dc8147ab5e57bb84220f5e59b 100644 (file)
@@ -1093,9 +1093,6 @@ PyImport_ImportModuleLevelObject:PyObject*:locals:0:???
 PyImport_ImportModuleLevelObject:PyObject*:fromlist:0:???
 PyImport_ImportModuleLevelObject:int:level::
 
-PyImport_ImportModuleNoBlock:PyObject*::+1:
-PyImport_ImportModuleNoBlock:const char*:name::
-
 PyImport_ReloadModule:PyObject*::+1:
 PyImport_ReloadModule:PyObject*:m:0:
 
index 3d68487d07baf276792fce0a3784915967e79329..a8658d8b80e2945811ba77a21df7876b2b01c0cb 100644 (file)
@@ -323,7 +323,6 @@ func,PyImport_ImportFrozenModuleObject,3.7,,
 func,PyImport_ImportModule,3.2,,
 func,PyImport_ImportModuleLevel,3.2,,
 func,PyImport_ImportModuleLevelObject,3.7,,
-func,PyImport_ImportModuleNoBlock,3.2,,
 func,PyImport_ReloadModule,3.2,,
 func,PyIndex_Check,3.8,,
 type,PyInterpreterState,3.2,,opaque
index a5cc8f1d5b34753c5e5fcc8921074c1cba5bc886..a391566c82c2f1e87d58f1bd3c416c239ffb3d55 100644 (file)
@@ -2,7 +2,7 @@ Pending removal in Python 3.15
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 * The bundled copy of ``libmpdecimal``.
-* The :c:func:`PyImport_ImportModuleNoBlock`:
+* The :c:func:`!PyImport_ImportModuleNoBlock`:
   Use :c:func:`PyImport_ImportModule` instead.
 * :c:func:`PyWeakref_GetObject` and :c:func:`PyWeakref_GET_OBJECT`:
   Use :c:func:`PyWeakref_GetRef` instead. The `pythoncapi-compat project
index 9dbc07a34e20a1d38d6a1cf14d94a0fe7c767502..0803eba99e6d172b7d7b313424312bc29e3101e3 100644 (file)
@@ -3043,7 +3043,7 @@ Changes to Python's build process and to the C API include:
 
 * Importing modules simultaneously in two different threads no longer
   deadlocks; it will now raise an :exc:`ImportError`.  A new API
-  function, :c:func:`PyImport_ImportModuleNoBlock`, will look for a
+  function, :c:func:`!PyImport_ImportModuleNoBlock`, will look for a
   module in ``sys.modules`` first, then try to import it after
   acquiring an import lock.  If the import lock is held by another
   thread, an :exc:`ImportError` is raised.
index 6e1fda22ed203ac2320d371b6db14d8e8a9d1af7..d858586138e9aea128fc698c9928c87741c1f24a 100644 (file)
@@ -870,7 +870,7 @@ to the C API.
 * :c:func:`!PyNumber_Coerce`, :c:func:`!PyNumber_CoerceEx`,
   :c:func:`!PyMember_Get`, and :c:func:`!PyMember_Set` C APIs are removed.
 
-* New C API :c:func:`PyImport_ImportModuleNoBlock`, works like
+* New C API :c:func:`!PyImport_ImportModuleNoBlock`, works like
   :c:func:`PyImport_ImportModule` but won't block on the import lock
   (returning an error instead).
 
index e20e49325c01d591381467f04163d58bfea14012..ff33224e272c67cbb991e47ce44075f45fcc7014 100644 (file)
@@ -2499,7 +2499,7 @@ Deprecated C APIs
   which return a :term:`borrowed reference`.
   (Soft deprecated as part of :pep:`667`.)
 
-* Deprecate the :c:func:`PyImport_ImportModuleNoBlock` function,
+* 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`.)
 
index b4ed79ff0885cb8ac2e6a8a98397a1b10a35f9f0..7131eeb697eb6909abc6bde6725efb484b9a4a75 100644 (file)
@@ -164,3 +164,5 @@ Deprecated C APIs
 Removed C APIs
 --------------
 
+* :c:func:`!PyImport_ImportModuleNoBlock`: deprecated alias
+  of :c:func:`PyImport_ImportModule`.
index 7a8eb47cbdb354e7fe23fbae630448d81df086aa..89fd68686454e27e86e0fc95544b978edfff3da0 100644 (file)
@@ -829,7 +829,7 @@ Previous versions of CPython have always relied on a global import lock.
 This led to unexpected annoyances, such as deadlocks when importing a module
 would trigger code execution in a different thread as a side-effect.
 Clumsy workarounds were sometimes employed, such as the
-:c:func:`PyImport_ImportModuleNoBlock` C API function.
+:c:func:`!PyImport_ImportModuleNoBlock` C API function.
 
 In Python 3.3, importing a module takes a per-module lock.  This correctly
 serializes importation of a given module from multiple threads (preventing
index 24b23b9119196fcb5908ae70e035a884543bcc05..d91ebe96ca868d139168c3a0c1333fbba001dee9 100644 (file)
@@ -51,9 +51,6 @@ PyAPI_FUNC(PyObject *) PyImport_AddModuleRef(
 PyAPI_FUNC(PyObject *) PyImport_ImportModule(
     const char *name            /* UTF-8 encoded string */
     );
-Py_DEPRECATED(3.13) PyAPI_FUNC(PyObject *) PyImport_ImportModuleNoBlock(
-    const char *name            /* UTF-8 encoded string */
-    );
 PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevel(
     const char *name,           /* UTF-8 encoded string */
     PyObject *globals,
index 25136624ca4ed9b9a5b725efad9621cc3e5900bd..57e0316fda8a52b1e2816da4688db2b6fa727b91 100644 (file)
@@ -134,7 +134,7 @@ class ImportTests(unittest.TestCase):
         # CRASHES importmodule(NULL)
 
     def test_importmodulenoblock(self):
-        # Test deprecated PyImport_ImportModuleNoBlock()
+        # Test deprecated (stable ABI only) PyImport_ImportModuleNoBlock()
         importmodulenoblock = _testlimitedcapi.PyImport_ImportModuleNoBlock
         with check_warnings(('', DeprecationWarning)):
             self.check_import_func(importmodulenoblock)
index a2d3620204588745bbdf59773f07898d79690fe8..47cbf33c3bb29b21f3a556ca4d988a8153b16981 100644 (file)
@@ -1161,7 +1161,7 @@ no-op now.
 .. nonce: Lq2_gR
 .. section: C API
 
-Replaced deprecated usage of :c:func:`PyImport_ImportModuleNoBlock` with
+Replaced deprecated usage of :c:func:`!PyImport_ImportModuleNoBlock` with
 :c:func:`PyImport_ImportModule` in stdlib modules. Patch by Kumar Aditya.
 
 ..
index 91e9fee7e37437d7aaaf6b1c0e1f3d4b771ac56d..6149b33b07606667fb6fda3cfd26c27f31e2afac 100644 (file)
@@ -6538,7 +6538,7 @@ to hide implementation details. Patch by Victor Stinner.
 .. nonce: FQJG5B
 .. section: C API
 
-Deprecate the :c:func:`PyImport_ImportModuleNoBlock` function which is just
+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/Misc/NEWS.d/next/C_API/2025-05-08-12-25-47.gh-issue-133644.Yb86Rm.rst b/Misc/NEWS.d/next/C_API/2025-05-08-12-25-47.gh-issue-133644.Yb86Rm.rst
new file mode 100644 (file)
index 0000000..9569456
--- /dev/null
@@ -0,0 +1,2 @@
+Remove deprecated alias :c:func:`!PyImport_ImportModuleNoBlock` of
+:c:func:`PyImport_ImportModule`. Patch by Bénédikt Tran.
index d3e1f0db05702390dc013947b4f5d9027f874572..886979139ee8a689182d37d4f0554a1e050927b0 100644 (file)
     added = '3.2'
 [function.PyImport_ImportModuleNoBlock]
     added = '3.2'
+    abi_only = true
 [function.PyImport_ReloadModule]
     added = '3.2'
 [function.PyInterpreterState_Clear]
index 3707dbedeea0d998d204c2cdccaf2ef3b9a707c9..f85daee57d712e76d24fa6ca0ac12adcc4b9c955 100644 (file)
@@ -108,20 +108,19 @@ pyimport_importmodule(PyObject *Py_UNUSED(module), PyObject *args)
 }
 
 
-/* Test PyImport_ImportModuleNoBlock() */
+/* Test PyImport_ImportModuleNoBlock() (removed in 3.15) */
 static PyObject *
 pyimport_importmodulenoblock(PyObject *Py_UNUSED(module), PyObject *args)
 {
+    // Get the function from the stable ABI.
+    PyAPI_FUNC(PyObject *) PyImport_ImportModuleNoBlock(const char *name);
+
     const char *name;
     Py_ssize_t size;
     if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
         return NULL;
     }
-
-    _Py_COMP_DIAG_PUSH
-    _Py_COMP_DIAG_IGNORE_DEPR_DECLS
     return PyImport_ImportModuleNoBlock(name);
-    _Py_COMP_DIAG_POP
 }
 
 
index afdc28eda31b9b952bc820b4083242843cd3e21a..9dec0f488a3b905e4517652d095d6045620d5f2e 100644 (file)
@@ -3434,8 +3434,10 @@ PyImport_ImportModule(const char *name)
  * ImportError instead of blocking.
  *
  * Returns the module object with incremented ref count.
+ *
+ * Removed in 3.15, but kept for stable ABI compatibility.
  */
-PyObject *
+PyAPI_FUNC(PyObject *)
 PyImport_ImportModuleNoBlock(const char *name)
 {
     if (PyErr_WarnEx(PyExc_DeprecationWarning,