Skip to content

Commit 522267e

Browse files
committed
Issue #15610: The PyImport_ImportModuleEx macro now calls
PyImport_ImportModuleLevel() with a 'level' of 0 instead of -1 as the latter is no longer a valid value. Also added a versionchanged note for PyImport_ImportModuleLevel() just in case people don't make the connection between changes to __import__() and this C function.
1 parent f410ce8 commit 522267e

4 files changed

Lines changed: 13 additions & 3 deletions

File tree

Doc/c-api/import.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ Importing Modules
4444
.. index:: builtin: __import__
4545
4646
Import a module. This is best described by referring to the built-in Python
47-
function :func:`__import__`, as the standard :func:`__import__` function calls
48-
this function directly.
47+
function :func:`__import__`.
4948
5049
The return value is a new reference to the imported module or top-level
5150
package, or *NULL* with an exception set on failure. Like for
@@ -76,6 +75,9 @@ Importing Modules
7675
Similar to :c:func:`PyImport_ImportModuleLevelObject`, but the name is an
7776
UTF-8 encoded string instead of a Unicode object.
7877
78+
.. versionchanged:: 3.3
79+
Negative values for **level** are no longer accepted.
80+
7981
.. c:function:: PyObject* PyImport_Import(PyObject *name)
8082
8183
This is a higher-level interface that calls the current "import hook

Doc/whatsnew/3.3.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,11 @@ Porting C code
18801880

18811881
* :c:func:`PyImport_GetMagicNumber` now returns -1 upon failure.
18821882

1883+
* As a negative value for the **level** argument to :func:`__import__` is no
1884+
longer valid, the same now holds for :c:func:`PyImport_ImportModuleLevel`.
1885+
This also means that the value of **level** used by
1886+
:c:func:`PyImport_ImportModuleEx` is now 0 instead of -1.
1887+
18831888

18841889
Building C extensions
18851890
---------------------

Include/import.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevelObject(
6262
);
6363

6464
#define PyImport_ImportModuleEx(n, g, l, f) \
65-
PyImport_ImportModuleLevel(n, g, l, f, -1)
65+
PyImport_ImportModuleLevel(n, g, l, f, 0)
6666

6767
PyAPI_FUNC(PyObject *) PyImport_GetImporter(PyObject *path);
6868
PyAPI_FUNC(PyObject *) PyImport_Import(PyObject *name);

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ Library
237237
C API
238238
-----
239239

240+
- Issue #15610: PyImport_ImportModuleEx() now uses a 'level' of 0 instead of
241+
-1.
242+
240243
- Issues #15169, #14599: Strip out the C implementation of
241244
imp.source_from_cache() used by PyImport_ExecCodeModuleWithPathnames() and
242245
used the Python code instead. Leads to PyImport_ExecCodeModuleObject() to not

0 commit comments

Comments
 (0)