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 /Modules/itertoolsmodule.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 'Modules/itertoolsmodule.c')
-rw-r--r-- | Modules/itertoolsmodule.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 985915f..1113fb6 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -830,17 +830,15 @@ tee(PyObject *self, PyObject *args) return NULL; } - copyfunc = _PyObject_GetAttrId(it, &PyId___copy__); - if (copyfunc != NULL) { - copyable = it; - } - else if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { + if (_PyObject_LookupAttrId(it, &PyId___copy__, ©func) < 0) { Py_DECREF(it); Py_DECREF(result); return NULL; } + if (copyfunc != NULL) { + copyable = it; + } else { - PyErr_Clear(); copyable = tee_fromiterable(it); Py_DECREF(it); if (copyable == NULL) { |