gh-128911: Use PyImport_ImportModuleAttr() function (#129657)

* Replace PyImport_ImportModule() + PyObject_GetAttr() with
  PyImport_ImportModuleAttr().
* Replace PyImport_ImportModule() + PyObject_GetAttrString() with
  PyImport_ImportModuleAttrString().
This commit is contained in:
Victor Stinner 2025-02-05 11:03:58 +01:00 committed by GitHub
parent fb5d1c9236
commit dc804ffb2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 32 additions and 84 deletions

View file

@ -368,12 +368,9 @@ _convert_exc_to_TracebackException(PyObject *exc, PyObject **p_tbexc)
PyObject *create = NULL;
// This is inspired by _PyErr_Display().
PyObject *tbmod = PyImport_ImportModule("traceback");
if (tbmod == NULL) {
return -1;
}
PyObject *tbexc_type = PyObject_GetAttrString(tbmod, "TracebackException");
Py_DECREF(tbmod);
PyObject *tbexc_type = PyImport_ImportModuleAttrString(
"traceback",
"TracebackException");
if (tbexc_type == NULL) {
return -1;
}