mirror of
https://github.com/python/cpython.git
synced 2025-08-29 21:25:01 +00:00
gh-93741: Add private C API _PyImport_GetModuleAttrString() (GH-93742)
It combines PyImport_ImportModule() and PyObject_GetAttrString() and saves 4-6 lines of code on every use. Add also _PyImport_GetModuleAttr() which takes Python strings as arguments.
This commit is contained in:
parent
7b2064b4b9
commit
6fd4c8ec77
24 changed files with 114 additions and 248 deletions
|
@ -2342,19 +2342,15 @@ error:
|
|||
static PyStatus
|
||||
init_set_builtins_open(void)
|
||||
{
|
||||
PyObject *iomod = NULL, *wrapper;
|
||||
PyObject *wrapper;
|
||||
PyObject *bimod = NULL;
|
||||
PyStatus res = _PyStatus_OK();
|
||||
|
||||
if (!(iomod = PyImport_ImportModule("io"))) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(bimod = PyImport_ImportModule("builtins"))) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(wrapper = PyObject_GetAttrString(iomod, "open"))) {
|
||||
if (!(wrapper = _PyImport_GetModuleAttrString("io", "open"))) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -2371,7 +2367,6 @@ error:
|
|||
|
||||
done:
|
||||
Py_XDECREF(bimod);
|
||||
Py_XDECREF(iomod);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue