Issue #3080: Add PyImport_ImportModuleLevelObject() function · pythoncapi/cpython@fe93faf · GitHub
Skip to content

Commit fe93faf

Browse files
author
Victor Stinner
committed
Issue python#3080: Add PyImport_ImportModuleLevelObject() function
Use it for the builtin __import__ function.
1 parent 98dbba5 commit fe93faf

4 files changed

Lines changed: 41 additions & 18 deletions

File tree

Doc/c-api/import.rst

Lines changed: 8 additions & 1 deletion

Include/import.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevel(
5050
PyObject *fromlist,
5151
int level
5252
);
53+
PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevelObject(
54+
PyObject *name,
55+
PyObject *globals,
56+
PyObject *locals,
57+
PyObject *fromlist,
58+
int level
59+
);
5360

5461
#define PyImport_ImportModuleEx(n, g, l, f) \
5562
PyImport_ImportModuleLevel(n, g, l, f, -1)

Python/bltinmodule.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,14 @@ builtin___import__(PyObject *self, PyObject *args, PyObject *kwds)
155155
{
156156
static char *kwlist[] = {"name", "globals", "locals", "fromlist",
157157
"level", 0};
158-
char *name;
159-
PyObject *globals = NULL;
160-
PyObject *locals = NULL;
161-
PyObject *fromlist = NULL;
158+
PyObject *name, *globals = NULL, *locals = NULL, *fromlist = NULL;
162159
int level = -1;
163160

164-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|OOOi:__import__",
161+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "U|OOOi:__import__",
165162
kwlist, &name, &globals, &locals, &fromlist, &level))
166163
return NULL;
167-
return PyImport_ImportModuleLevel(name, globals, locals,
168-
fromlist, level);
164+
return PyImport_ImportModuleLevelObject(name, globals, locals,
165+
fromlist, level);
169166
}
170167

171168
PyDoc_STRVAR(import_doc,

Python/import.c

Lines changed: 22 additions & 10 deletions

0 commit comments

Comments
 (0)