summaryrefslogtreecommitdiffstats
path: root/Python/codecs.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-01-25 08:49:40 (GMT)
committerINADA Naoki <methane@users.noreply.github.com>2018-01-25 08:49:40 (GMT)
commitf320be77ffb73e3b9e7fc98c37b8df3975d84b40 (patch)
tree552338f0200938249233fa4aa7b00add61965337 /Python/codecs.c
parent2b822a0bb1de2612c85d8f75e3ce89eda2ac9f68 (diff)
downloadcpython-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/codecs.c')
-rw-r--r--Python/codecs.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/Python/codecs.c b/Python/codecs.c
index 18edfbd..223ccca 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) {