mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
GH-94254: Make _struct module types immutable (GH-94269)
(cherry picked from commit 17ed560fcd
)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
This commit is contained in:
parent
4b1144ced1
commit
c481cd6256
3 changed files with 17 additions and 2 deletions
|
@ -689,6 +689,18 @@ class StructTest(unittest.TestCase):
|
|||
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':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue