Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions 6 Lib/test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def test_bad_constructor(self):
self.assertRaises(TypeError, array.array, 'xx')
self.assertRaises(ValueError, array.array, 'x')

@support.cpython_only
def test_immutable(self):
Comment thread
erlend-aasland marked this conversation as resolved.
# 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')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Make the :class:`array.array` type immutable. Patch by
Erlend E. Aasland.
3 changes: 2 additions & 1 deletion 3 Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2847,7 +2847,8 @@ static PyType_Slot array_slots[] = {
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,
};

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.