diff options
-rw-r--r-- | Lib/test/test_builtin.py | 4 | ||||
-rw-r--r-- | Objects/typeobject.c | 6 |
2 files changed, 5 insertions, 5 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index be6f391ba8..c5bb54a52e 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -558,6 +558,10 @@ class BuiltinTest(unittest.TestCase): # TypeError because self.__format__ returns the wrong type self.assertRaises(TypeError, format, B(), "") + # TypeError because format_spec is not unicode + self.assertRaises(TypeError, format, object(), 4) + self.assertRaises(TypeError, format, object(), object()) + # make sure we can take a subclass of str as a format spec self.assertEqual(format(0, C('10')), ' 0') diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 2a0dd2458a..682c029126 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2950,12 +2950,8 @@ object_format(PyObject *self, PyObject *args) PyObject *result = NULL; PyObject *format_meth = NULL; - if (!PyArg_ParseTuple(args, "O:__format__", &format_spec)) + if (!PyArg_ParseTuple(args, "U:__format__", &format_spec)) return NULL; - if (!PyUnicode_Check(format_spec)) { - PyErr_SetString(PyExc_TypeError, "Unicode object required"); - return NULL; - } self_as_str = PyObject_Str(self); if (self_as_str != NULL) { |