diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-01-25 08:49:40 (GMT) |
---|---|---|
committer | INADA Naoki <methane@users.noreply.github.com> | 2018-01-25 08:49:40 (GMT) |
commit | f320be77ffb73e3b9e7fc98c37b8df3975d84b40 (patch) | |
tree | 552338f0200938249233fa4aa7b00add61965337 /Python/_warnings.c | |
parent | 2b822a0bb1de2612c85d8f75e3ce89eda2ac9f68 (diff) | |
download | cpython-f320be77ffb73e3b9e7fc98c37b8df3975d84b40.zip cpython-f320be77ffb73e3b9e7fc98c37b8df3975d84b40.tar.gz cpython-f320be77ffb73e3b9e7fc98c37b8df3975d84b40.tar.bz2 |
bpo-32571: Avoid raising unneeded AttributeError and silencing it in C code (GH-5222)
Add two new private APIs: _PyObject_LookupAttr() and _PyObject_LookupAttrId()
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r-- | Python/_warnings.c | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index 20ba7a1..16ae932 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. */ |