Skip to content

Commit c6ad03f

Browse files
Erlend Egeberg Aaslandvstinner
Erlend Egeberg Aasland
andauthored
bpo-43908: Make array.array type immutable (GH-25696)
Co-authored-by: Victor Stinner <[email protected]>
1 parent 5daf70b commit c6ad03f

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Lib/test/test_array.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ def test_bad_constructor(self):
4040
self.assertRaises(TypeError, array.array, 'xx')
4141
self.assertRaises(ValueError, array.array, 'x')
4242

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+
4349
def test_empty(self):
4450
# Exercise code for handling zero-length arrays
4551
a = array.array('B')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Make the :class:`array.array` type immutable. Patch by
2+
Erlend E. Aasland.

Modules/arraymodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2847,7 +2847,8 @@ static PyType_Slot array_slots[] = {
28472847
static PyType_Spec array_spec = {
28482848
.name = "array.array",
28492849
.basicsize = sizeof(arrayobject),
2850-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
2850+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
2851+
Py_TPFLAGS_IMMUTABLETYPE),
28512852
.slots = array_slots,
28522853
};
28532854

0 commit comments

Comments
 (0)