summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-06-26 10:45:00 (GMT)
committerGitHub <noreply@github.com>2022-06-26 10:45:00 (GMT)
commitc481cd6256f0e4493fa28f26c5902101803abadb (patch)
tree69bfd6c832289df28de763e7c0830f89708107b7 /Lib/test
parent4b1144ced142be2765f5d14c9632cee2b75748f2 (diff)
downloadcpython-c481cd6256f0e4493fa28f26c5902101803abadb.zip
cpython-c481cd6256f0e4493fa28f26c5902101803abadb.tar.gz
cpython-c481cd6256f0e4493fa28f26c5902101803abadb.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')
-rw-r--r--Lib/test/test_struct.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index 5c2dfab..5a9b5de 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':