From f320be77ffb73e3b9e7fc98c37b8df3975d84b40 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 25 Jan 2018 10:49:40 +0200 Subject: bpo-32571: Avoid raising unneeded AttributeError and silencing it in C code (GH-5222) Add two new private APIs: _PyObject_LookupAttr() and _PyObject_LookupAttrId() --- Python/_warnings.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'Python/_warnings.c') diff --git a/Python/_warnings.c b/Python/_warnings.c index 20ba7a1661..16ae932450 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -80,11 +80,8 @@ get_warnings_attr(_Py_Identifier *attr_id, int try_import) return NULL; } - obj = _PyObject_GetAttrId(warnings_module, attr_id); + (void)_PyObject_LookupAttrId(warnings_module, attr_id, &obj); Py_DECREF(warnings_module); - if (obj == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - } return obj; } @@ -893,13 +890,10 @@ get_source_line(PyObject *module_globals, int lineno) Py_INCREF(module_name); /* Make sure the loader implements the optional get_source() method. */ - get_source = _PyObject_GetAttrId(loader, &PyId_get_source); + (void)_PyObject_LookupAttrId(loader, &PyId_get_source, &get_source); Py_DECREF(loader); if (!get_source) { Py_DECREF(module_name); - if (PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - } return NULL; } /* Call get_source() to get the source code. */ -- cgit v1.2.1