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/codecs.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'Python/codecs.c') diff --git a/Python/codecs.c b/Python/codecs.c index 18edfbdab9..223ccca603 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -540,15 +540,11 @@ PyObject * _PyCodec_LookupTextEncoding(const char *encoding, * attribute. */ if (!PyTuple_CheckExact(codec)) { - attr = _PyObject_GetAttrId(codec, &PyId__is_text_encoding); - if (attr == NULL) { - if (PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - } else { - Py_DECREF(codec); - return NULL; - } - } else { + if (_PyObject_LookupAttrId(codec, &PyId__is_text_encoding, &attr) < 0) { + Py_DECREF(codec); + return NULL; + } + if (attr != NULL) { is_text_codec = PyObject_IsTrue(attr); Py_DECREF(attr); if (is_text_codec <= 0) { -- cgit v1.2.1