# HG changeset patch # Parent cdc3837cb1fcfc4273b46e84c533ec7e91246b71 Issue 16349: Bytes strings are allowed as struct format strings diff -r cdc3837cb1fc Doc/library/struct.rst --- a/Doc/library/struct.rst Tue Dec 16 03:21:54 2014 -0500 +++ b/Doc/library/struct.rst Thu Dec 18 05:45:37 2014 +0000 @@ -100,7 +100,8 @@ Format strings are the mechanism used to specify the expected layout when packing and unpacking data. They are built up from :ref:`format-characters`, which specify the type of data being packed/unpacked. In addition, there are -special characters for controlling the :ref:`struct-alignment`. +special characters for controlling the :ref:`struct-alignment`. They are +normally character strings, but ASCII byte strings are also acceptable. .. _struct-alignment: diff -r cdc3837cb1fc Lib/test/test_struct.py --- a/Lib/test/test_struct.py Tue Dec 16 03:21:54 2014 -0500 +++ b/Lib/test/test_struct.py Thu Dec 18 05:45:37 2014 +0000 @@ -590,6 +590,11 @@ self.check_sizeof('0s', 1) self.check_sizeof('0c', 0) + def test_bytes_format(self): + """Make sure bytes strings are accepted as format strings""" + self.assertEqual(b"\x00", struct.Struct(b"x").pack()) + self.assertEqual(b"\x00", struct.pack(b"x")) + class UnpackIteratorTest(unittest.TestCase): """