There was an error while loading. Please reload this page.
1 parent 5daf70b commit c6ad03fCopy full SHA for c6ad03f
3 files changed
Lib/test/test_array.py
@@ -40,6 +40,12 @@ def test_bad_constructor(self):
40
self.assertRaises(TypeError, array.array, 'xx')
41
self.assertRaises(ValueError, array.array, 'x')
42
43
+ @support.cpython_only
44
+ def test_immutable(self):
45
+ # bpo-43908: check that array.array is immutable
46
+ with self.assertRaises(TypeError):
47
+ array.array.foo = 1
48
+
49
def test_empty(self):
50
# Exercise code for handling zero-length arrays
51
a = array.array('B')
Misc/NEWS.d/next/Core and Builtins/2021-04-26-20-59-17.bpo-43908.-COW4-.rst
@@ -0,0 +1,2 @@
1
+Make the :class:`array.array` type immutable. Patch by
2
+Erlend E. Aasland.
Modules/arraymodule.c
@@ -2847,7 +2847,8 @@ static PyType_Slot array_slots[] = {
2847
static PyType_Spec array_spec = {
2848
.name = "array.array",
2849
.basicsize = sizeof(arrayobject),
2850
- .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
2851
+ Py_TPFLAGS_IMMUTABLETYPE),
2852
.slots = array_slots,
2853
};
2854
0 commit comments