diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-06-26 10:42:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-26 10:42:41 (GMT) |
commit | 5ce819f3c50a30074c843d57c3488a911e4fa578 (patch) | |
tree | b940866a4a70963454604cf09375fb763c4a6c97 /Lib/test/test_struct.py | |
parent | ad23df97edb09f5d824bc6b0d1cc89c1637023af (diff) | |
download | cpython-5ce819f3c50a30074c843d57c3488a911e4fa578.zip cpython-5ce819f3c50a30074c843d57c3488a911e4fa578.tar.gz cpython-5ce819f3c50a30074c843d57c3488a911e4fa578.tar.bz2 |
GH-94254: Make _struct module types immutable (GH-94269)
(cherry picked from commit 17ed560fcd0a1442485f9bd48884bbe412f35abc)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_struct.py')
-rw-r--r-- | Lib/test/test_struct.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index 8f14ed3..ab73877 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -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': |