mirror of
https://github.com/python/cpython
synced 2024-09-16 01:09:38 +00:00
GH-94254: Make _struct module types immutable (#94269)
This commit is contained in:
parent
27934bef2d
commit
17ed560fcd
|
@ -689,6 +689,18 @@ def test__struct_reference_cycle_cleaned_up(self):
|
|||
self.assertIsNone(
|
||||
module_ref(), "_struct module was not garbage collected")
|
||||
|
||||
@support.cpython_only
|
||||
def test__struct_types_immutable(self):
|
||||
# See https://github.com/python/cpython/issues/94254
|
||||
|
||||
Struct = struct.Struct
|
||||
unpack_iterator = type(struct.iter_unpack("b", b'x'))
|
||||
for cls in (Struct, unpack_iterator):
|
||||
with self.subTest(cls=cls):
|
||||
with self.assertRaises(TypeError):
|
||||
cls.x = 1
|
||||
|
||||
|
||||
def test_issue35714(self):
|
||||
# Embedded null characters should not be allowed in format strings.
|
||||
for s in '\0', '2\0i', b'\0':
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fixed types of :mod:`struct` module to be immutable. Patch by Kumar Aditya.
|
|
@ -1741,7 +1741,8 @@ static PyType_Spec unpackiter_type_spec = {
|
|||
"_struct.unpack_iterator",
|
||||
sizeof(unpackiterobject),
|
||||
0,
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
|
||||
(Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
||||
Py_TPFLAGS_IMMUTABLETYPE),
|
||||
unpackiter_type_slots
|
||||
};
|
||||
|
||||
|
@ -2110,7 +2111,8 @@ static PyType_Spec PyStructType_spec = {
|
|||
"_struct.Struct",
|
||||
sizeof(PyStructObject),
|
||||
0,
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
|
||||
(Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
||||
Py_TPFLAGS_BASETYPE | Py_TPFLAGS_IMMUTABLETYPE),
|
||||
PyStructType_slots
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue