mirror of
https://github.com/python/cpython.git
synced 2026-04-23 12:21:01 +00:00
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.
(cherry picked from commit e890421e33)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
91b863d93b
commit
1370832af2
4 changed files with 24 additions and 5 deletions
|
|
@ -2597,7 +2597,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 */
|
||||
}
|
||||
|
|
@ -2779,6 +2779,9 @@ PyBytes_FromObject(PyObject *x)
|
|||
Py_DECREF(it);
|
||||
return result;
|
||||
}
|
||||
if (!PyErr_ExceptionMatches(PyExc_TypeError)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue