Co-authored-by: Victor Stinner <vstinner@python.org>
self.assertRaises(TypeError, array.array, 'xx')
self.assertRaises(ValueError, array.array, 'x')
+ @support.cpython_only
+ def test_immutable(self):
+ # bpo-43908: check that array.array is immutable
+ with self.assertRaises(TypeError):
+ array.array.foo = 1
+
def test_empty(self):
# Exercise code for handling zero-length arrays
a = array.array('B')
--- /dev/null
+Make the :class:`array.array` type immutable. Patch by
+Erlend E. Aasland.
static PyType_Spec array_spec = {
.name = "array.array",
.basicsize = sizeof(arrayobject),
- .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_IMMUTABLETYPE),
.slots = array_slots,
};