gh-121249: unconditionally support complex types in struct (GH-132864)

Co-authored-by: Lisandro Dalcin <dalcinl@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
Sergey B Kirpichev 2025-05-02 19:24:52 +03:00 committed by GitHub
parent e6c518d2eb
commit f425509349
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 21 additions and 89 deletions

View file

@ -22,12 +22,6 @@
INF = float('inf')
NAN = float('nan')
try:
struct.pack('D', 1j)
have_c_complex = True
except struct.error:
have_c_complex = False
def iter_integer_formats(byteorders=byteorders):
for code in integer_codes:
for byteorder in byteorders:
@ -796,7 +790,6 @@ def test_repr(self):
s = struct.Struct('=i2H')
self.assertEqual(repr(s), f'Struct({s.format!r})')
@unittest.skipUnless(have_c_complex, "requires C11 complex type support")
def test_c_complex_round_trip(self):
values = [complex(*_) for _ in combinations([1, -1, 0.0, -0.0, 2,
-3, INF, -INF, NAN], 2)]
@ -806,19 +799,6 @@ def test_c_complex_round_trip(self):
round_trip = struct.unpack(f, struct.pack(f, z))[0]
self.assertComplexesAreIdentical(z, round_trip)
@unittest.skipIf(have_c_complex, "requires no C11 complex type support")
def test_c_complex_error(self):
msg1 = "'F' format not supported on this system"
msg2 = "'D' format not supported on this system"
with self.assertRaisesRegex(struct.error, msg1):
struct.pack('F', 1j)
with self.assertRaisesRegex(struct.error, msg1):
struct.unpack('F', b'1')
with self.assertRaisesRegex(struct.error, msg2):
struct.pack('D', 1j)
with self.assertRaisesRegex(struct.error, msg2):
struct.unpack('D', b'1')
class UnpackIteratorTest(unittest.TestCase):
"""