diff -r 953d8ec1aeb3 Lib/test/test_struct.py --- a/Lib/test/test_struct.py Sat Dec 14 21:07:51 2013 +0200 +++ b/Lib/test/test_struct.py Sun Dec 15 22:37:33 2013 +0800 @@ -659,6 +659,13 @@ self.assertRaises(StopIteration, next, it) self.assertRaises(StopIteration, next, it) + def test_invalid_argument(self): + with self.assertRaises(TypeError) as cx: + struct.Struct(1) + self.assertEqual(str(cx.exception), + "Struct() argument 1 must be a string or bytes " + "object, not int") + def test_main(): support.run_unittest(__name__) diff -r 953d8ec1aeb3 Modules/_struct.c --- a/Modules/_struct.c Sat Dec 14 21:07:51 2013 +0200 +++ b/Modules/_struct.c Sun Dec 15 22:37:33 2013 +0800 @@ -1432,8 +1432,8 @@ if (!PyBytes_Check(o_format)) { Py_DECREF(o_format); PyErr_Format(PyExc_TypeError, - "Struct() argument 1 must be a bytes object, not %.200s", - Py_TYPE(o_format)->tp_name); + "Struct() argument 1 must be a string or bytes object, " + "not %.200s", Py_TYPE(o_format)->tp_name); return -1; }