diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-09-01 11:01:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-01 11:01:05 (GMT) |
commit | 353053d9ad08fea0e205e6c008b8a4350c0188e6 (patch) | |
tree | 3bd4434c152e934fb260c1c1651c080c3df29a14 /Python/sysmodule.c | |
parent | 6922b9e4fce635339cb94c2fdef6bba4e2a99621 (diff) | |
download | cpython-353053d9ad08fea0e205e6c008b8a4350c0188e6.zip cpython-353053d9ad08fea0e205e6c008b8a4350c0188e6.tar.gz cpython-353053d9ad08fea0e205e6c008b8a4350c0188e6.tar.bz2 |
[3.8] bpo-37994: Fix silencing all errors if an attribute lookup fails. (GH-15630) (GH-15635)
Only AttributeError should be silenced.
(cherry picked from commit 41c57b335330ff48af098d47e379e0f9ba09d233)
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 93ffce2..11c20cf 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -201,16 +201,12 @@ PySys_Audit(const char *event, const char *argFormat, ...) ts->tracing++; ts->use_tracing = 0; while ((hook = PyIter_Next(hooks)) != NULL) { + _Py_IDENTIFIER(__cantrace__); PyObject *o; - int canTrace = -1; - o = PyObject_GetAttrString(hook, "__cantrace__"); + int canTrace = _PyObject_LookupAttrId(hook, &PyId___cantrace__, &o); if (o) { canTrace = PyObject_IsTrue(o); Py_DECREF(o); - } else if (PyErr_Occurred() && - PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - canTrace = 0; } if (canTrace < 0) { break; @@ -538,7 +534,10 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) if (encoded == NULL) goto error; - buffer = _PyObject_GetAttrId(outf, &PyId_buffer); + if (_PyObject_LookupAttrId(outf, &PyId_buffer, &buffer) < 0) { + Py_DECREF(encoded); + goto error; + } if (buffer) { result = _PyObject_CallMethodIdObjArgs(buffer, &PyId_write, encoded, NULL); Py_DECREF(buffer); @@ -548,7 +547,6 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) Py_DECREF(result); } else { - PyErr_Clear(); escaped_str = PyUnicode_FromEncodedObject(encoded, stdout_encoding_str, "strict"); |