bpo-21071: struct.Struct.format type is now str by vstinner · Pull Request #845 · python/cpython (original) (raw)

Expand Up

@@ -618,6 +618,14 @@ def test_issue29802(self):

# Shouldn't crash.

self.assertEqual(struct.unpack(b'b', b'a'), (b'a'[0],))

def test_format_attr(self):

s = struct.Struct('=i2H')

self.assertEqual(s.format, '=i2H')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, self.assertIsInstance(s.format, str) would be better to understand (for future readers) the behavior change.

# use a bytes string

s2 = struct.Struct(s.format.encode())

self.assertEqual(s2.format, s.format)

class UnpackIteratorTest(unittest.TestCase):

"""

Expand Down