GH-78724: Initialize struct.Struct in __new__ (GH-94532)

Closes https://github.com/python/cpython/issues/75960
Closes https://github.com/python/cpython/issues/78724
This commit is contained in:
Kumar Aditya 2022-09-25 19:02:48 +05:30 committed by GitHub
parent f5f047aa62
commit c8c0afc713
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 41 deletions

View file

@ -700,6 +700,20 @@ class StructTest(unittest.TestCase):
with self.assertRaises(TypeError):
cls.x = 1
@support.cpython_only
def test__struct_Struct__new__initialized(self):
# See https://github.com/python/cpython/issues/78724
s = struct.Struct.__new__(struct.Struct, "b")
s.unpack_from(b"abcd")
@support.cpython_only
def test__struct_Struct_subclassing(self):
class Bob(struct.Struct):
pass
s = Bob("b")
s.unpack_from(b"abcd")
def test_issue35714(self):
# Embedded null characters should not be allowed in format strings.