Index: Objects/bytearrayobject.c =================================================================== --- Objects/bytearrayobject.c (revision 80103) +++ Objects/bytearrayobject.c (working copy) @@ -636,6 +636,11 @@ needed = 0; } else if (values == (PyObject *)self || !PyByteArray_Check(values)) { + if(PyNumber_Check(values)) { + PyErr_SetString(PyExc_TypeError, + "can assign only encoded strings, buffers, and iterables"); + return -1; + } /* Make a copy an call this function recursively */ int err; values = PyByteArray_FromObject(values); Index: Lib/test/test_bytes.py =================================================================== --- Lib/test/test_bytes.py (revision 80103) +++ Lib/test/test_bytes.py (working copy) @@ -564,6 +564,9 @@ b[3:0] = [42, 42, 42] self.assertEqual(b, bytearray([0, 1, 2, 42, 42, 42, 3, 4, 5, 6, 7, 8, 9])) + with self.assertRaises(TypeError): + b[3:4] = 5 + def test_extended_set_del_slice(self): indices = (0, None, 1, 3, 19, 300, 1<<333, -1, -2, -31, -300) for start in indices: