Skip to content

Commit a2c4467

Browse files
authored
gh-133644: remove deprecated PyImport_ImportModuleNoBlock (#133655)
1 parent 26839ea commit a2c4467

File tree

17 files changed

+20
-34
lines changed

17 files changed

+20
-34
lines changed

Doc/c-api/import.rst

-13
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@ Importing Modules
1616
This is a wrapper around :c:func:`PyImport_Import()` which takes a
1717
:c:expr:`const char *` as an argument instead of a :c:expr:`PyObject *`.
1818
19-
.. c:function:: PyObject* PyImport_ImportModuleNoBlock(const char *name)
20-
21-
This function is a deprecated alias of :c:func:`PyImport_ImportModule`.
22-
23-
.. versionchanged:: 3.3
24-
This function used to fail immediately when the import lock was held
25-
by another thread. In Python 3.3 though, the locking scheme switched
26-
to per-module locks for most purposes, so this function's special
27-
behaviour isn't needed anymore.
28-
29-
.. deprecated-removed:: 3.13 3.15
30-
Use :c:func:`PyImport_ImportModule` instead.
31-
3219
3320
.. c:function:: PyObject* PyImport_ImportModuleEx(const char *name, PyObject *globals, PyObject *locals, PyObject *fromlist)
3421

Doc/data/refcounts.dat

-3
Original file line numberDiff line numberDiff line change
@@ -1093,9 +1093,6 @@ PyImport_ImportModuleLevelObject:PyObject*:locals:0:???
10931093
PyImport_ImportModuleLevelObject:PyObject*:fromlist:0:???
10941094
PyImport_ImportModuleLevelObject:int:level::
10951095

1096-
PyImport_ImportModuleNoBlock:PyObject*::+1:
1097-
PyImport_ImportModuleNoBlock:const char*:name::
1098-
10991096
PyImport_ReloadModule:PyObject*::+1:
11001097
PyImport_ReloadModule:PyObject*:m:0:
11011098

Doc/data/stable_abi.dat

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/deprecations/c-api-pending-removal-in-3.15.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Pending removal in Python 3.15
22
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33

44
* The bundled copy of ``libmpdecimal``.
5-
* The :c:func:`PyImport_ImportModuleNoBlock`:
5+
* The :c:func:`!PyImport_ImportModuleNoBlock`:
66
Use :c:func:`PyImport_ImportModule` instead.
77
* :c:func:`PyWeakref_GetObject` and :c:func:`PyWeakref_GET_OBJECT`:
88
Use :c:func:`PyWeakref_GetRef` instead. The `pythoncapi-compat project

Doc/whatsnew/2.6.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -3043,7 +3043,7 @@ Changes to Python's build process and to the C API include:
30433043

30443044
* Importing modules simultaneously in two different threads no longer
30453045
deadlocks; it will now raise an :exc:`ImportError`. A new API
3046-
function, :c:func:`PyImport_ImportModuleNoBlock`, will look for a
3046+
function, :c:func:`!PyImport_ImportModuleNoBlock`, will look for a
30473047
module in ``sys.modules`` first, then try to import it after
30483048
acquiring an import lock. If the import lock is held by another
30493049
thread, an :exc:`ImportError` is raised.

Doc/whatsnew/3.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ to the C API.
870870
* :c:func:`!PyNumber_Coerce`, :c:func:`!PyNumber_CoerceEx`,
871871
:c:func:`!PyMember_Get`, and :c:func:`!PyMember_Set` C APIs are removed.
872872

873-
* New C API :c:func:`PyImport_ImportModuleNoBlock`, works like
873+
* New C API :c:func:`!PyImport_ImportModuleNoBlock`, works like
874874
:c:func:`PyImport_ImportModule` but won't block on the import lock
875875
(returning an error instead).
876876

Doc/whatsnew/3.13.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2499,7 +2499,7 @@ Deprecated C APIs
24992499
which return a :term:`borrowed reference`.
25002500
(Soft deprecated as part of :pep:`667`.)
25012501

2502-
* Deprecate the :c:func:`PyImport_ImportModuleNoBlock` function,
2502+
* Deprecate the :c:func:`!PyImport_ImportModuleNoBlock` function,
25032503
which is just an alias to :c:func:`PyImport_ImportModule` since Python 3.3.
25042504
(Contributed by Victor Stinner in :gh:`105396`.)
25052505

Doc/whatsnew/3.15.rst

+2
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,5 @@ Deprecated C APIs
164164
Removed C APIs
165165
--------------
166166

167+
* :c:func:`!PyImport_ImportModuleNoBlock`: deprecated alias
168+
of :c:func:`PyImport_ImportModule`.

Doc/whatsnew/3.3.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ Previous versions of CPython have always relied on a global import lock.
829829
This led to unexpected annoyances, such as deadlocks when importing a module
830830
would trigger code execution in a different thread as a side-effect.
831831
Clumsy workarounds were sometimes employed, such as the
832-
:c:func:`PyImport_ImportModuleNoBlock` C API function.
832+
:c:func:`!PyImport_ImportModuleNoBlock` C API function.
833833

834834
In Python 3.3, importing a module takes a per-module lock. This correctly
835835
serializes importation of a given module from multiple threads (preventing

Include/import.h

-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ PyAPI_FUNC(PyObject *) PyImport_AddModuleRef(
5151
PyAPI_FUNC(PyObject *) PyImport_ImportModule(
5252
const char *name /* UTF-8 encoded string */
5353
);
54-
Py_DEPRECATED(3.13) PyAPI_FUNC(PyObject *) PyImport_ImportModuleNoBlock(
55-
const char *name /* UTF-8 encoded string */
56-
);
5754
PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevel(
5855
const char *name, /* UTF-8 encoded string */
5956
PyObject *globals,

Lib/test/test_capi/test_import.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_importmodule(self):
134134
# CRASHES importmodule(NULL)
135135

136136
def test_importmodulenoblock(self):
137-
# Test deprecated PyImport_ImportModuleNoBlock()
137+
# Test deprecated (stable ABI only) PyImport_ImportModuleNoBlock()
138138
importmodulenoblock = _testlimitedcapi.PyImport_ImportModuleNoBlock
139139
with check_warnings(('', DeprecationWarning)):
140140
self.check_import_func(importmodulenoblock)

Misc/NEWS.d/3.11.0a4.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ no-op now.
11611161
.. nonce: Lq2_gR
11621162
.. section: C API
11631163
1164-
Replaced deprecated usage of :c:func:`PyImport_ImportModuleNoBlock` with
1164+
Replaced deprecated usage of :c:func:`!PyImport_ImportModuleNoBlock` with
11651165
:c:func:`PyImport_ImportModule` in stdlib modules. Patch by Kumar Aditya.
11661166

11671167
..

Misc/NEWS.d/3.13.0a1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -6538,7 +6538,7 @@ to hide implementation details. Patch by Victor Stinner.
65386538
.. nonce: FQJG5B
65396539
.. section: C API
65406540
6541-
Deprecate the :c:func:`PyImport_ImportModuleNoBlock` function which is just
6541+
Deprecate the :c:func:`!PyImport_ImportModuleNoBlock` function which is just
65426542
an alias to :c:func:`PyImport_ImportModule` since Python 3.3. Patch by
65436543
Victor Stinner.
65446544

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove deprecated alias :c:func:`!PyImport_ImportModuleNoBlock` of
2+
:c:func:`PyImport_ImportModule`. Patch by Bénédikt Tran.

Misc/stable_abi.toml

+1
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,7 @@
888888
added = '3.2'
889889
[function.PyImport_ImportModuleNoBlock]
890890
added = '3.2'
891+
abi_only = true
891892
[function.PyImport_ReloadModule]
892893
added = '3.2'
893894
[function.PyInterpreterState_Clear]

Modules/_testlimitedcapi/import.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,19 @@ pyimport_importmodule(PyObject *Py_UNUSED(module), PyObject *args)
108108
}
109109

110110

111-
/* Test PyImport_ImportModuleNoBlock() */
111+
/* Test PyImport_ImportModuleNoBlock() (removed in 3.15) */
112112
static PyObject *
113113
pyimport_importmodulenoblock(PyObject *Py_UNUSED(module), PyObject *args)
114114
{
115+
// Get the function from the stable ABI.
116+
PyAPI_FUNC(PyObject *) PyImport_ImportModuleNoBlock(const char *name);
117+
115118
const char *name;
116119
Py_ssize_t size;
117120
if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
118121
return NULL;
119122
}
120-
121-
_Py_COMP_DIAG_PUSH
122-
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
123123
return PyImport_ImportModuleNoBlock(name);
124-
_Py_COMP_DIAG_POP
125124
}
126125

127126

Python/import.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -3434,8 +3434,10 @@ PyImport_ImportModule(const char *name)
34343434
* ImportError instead of blocking.
34353435
*
34363436
* Returns the module object with incremented ref count.
3437+
*
3438+
* Removed in 3.15, but kept for stable ABI compatibility.
34373439
*/
3438-
PyObject *
3440+
PyAPI_FUNC(PyObject *)
34393441
PyImport_ImportModuleNoBlock(const char *name)
34403442
{
34413443
if (PyErr_WarnEx(PyExc_DeprecationWarning,

0 commit comments

Comments
 (0)