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 e890421e334ccf0c000c6b29c4a521d86cd12f47)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 692b7be..3f3e6bc 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -41,7 +41,6 @@
     } else {
         PyObject *index = PyNumber_Index(arg);
         if (index == NULL) {
-            PyErr_Format(PyExc_TypeError, "an integer is required");
             *value = -1;
             return 0;
         }
@@ -821,7 +820,7 @@
     if (PyIndex_Check(arg)) {
         count = PyNumber_AsSsize_t(arg, PyExc_OverflowError);
         if (count == -1 && PyErr_Occurred()) {
-            if (PyErr_ExceptionMatches(PyExc_OverflowError))
+            if (!PyErr_ExceptionMatches(PyExc_TypeError))
                 return -1;
             PyErr_Clear();  /* fall through */
         }