bpo-34974: Do not replace unexpected errors in bytes() and bytearray(). (GH-9852)

bytes and bytearray constructors converted unexpected exceptions
(e.g. MemoryError and KeyboardInterrupt) to TypeError.
This commit is contained in:
Serhiy Storchaka 2018-10-15 00:02:57 +03:00 committed by GitHub
parent de2aea0ff0
commit e890421e33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 5 deletions

View file

@ -2596,7 +2596,7 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (PyIndex_Check(x)) {
size = PyNumber_AsSsize_t(x, PyExc_OverflowError);
if (size == -1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError))
if (!PyErr_ExceptionMatches(PyExc_TypeError))
return NULL;
PyErr_Clear(); /* fall through */
}
@ -2778,6 +2778,9 @@ PyBytes_FromObject(PyObject *x)
Py_DECREF(it);
return result;
}
if (!PyErr_ExceptionMatches(PyExc_TypeError)) {
return NULL;
}
}
PyErr_Format(PyExc_TypeError,