]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Simplifed argument parsing in object.__format__, added test case.
authorEric Smith <eric@trueblade.com>
Fri, 11 Jan 2008 00:17:22 +0000 (00:17 +0000)
committerEric Smith <eric@trueblade.com>
Fri, 11 Jan 2008 00:17:22 +0000 (00:17 +0000)
Lib/test/test_builtin.py
Objects/typeobject.c

index be6f391ba8f2866e9decf53e45c87bf0c0630dd7..c5bb54a52e91348268a2e6b5e2ee7d30029df8bb 100644 (file)
@@ -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')
 
index 2a0dd2458aa9b0ee00fd4f45033e7cfa21d0ffb9..682c029126a6ecf4ee1f0332e2dddf89422e76ed 100644 (file)
@@ -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) {