]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix SF # 635969, No error "not all arguments converted"
authorNeal Norwitz <nnorwitz@gmail.com>
Tue, 12 Nov 2002 23:01:12 +0000 (23:01 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Tue, 12 Nov 2002 23:01:12 +0000 (23:01 +0000)
When mwh added extended slicing, strings and unicode became mappings.
Thus, dict was set which prevented an error when doing:
newstr = 'format without a percent' % string_value

This fix raises an exception again when there are no formats
and % with a string value.

Lib/test/test_format.py
Objects/stringobject.c
Objects/unicodeobject.c

index b40e8202f1b6f2009d2378a3788c7f643d7b8b50..da4d85ab3c5bd865bb8d553bd74488451911aeb9 100644 (file)
@@ -221,6 +221,14 @@ if have_unicode:
 
 test_exc('%d', '1', TypeError, "int argument required")
 test_exc('%g', '1', TypeError, "float argument required")
+test_exc('no format', '1', TypeError, 
+         "not all arguments converted during string formatting")
+test_exc('no format', u'1', TypeError, 
+         "not all arguments converted during string formatting")
+test_exc(u'no format', '1', TypeError, 
+         "not all arguments converted during string formatting")
+test_exc(u'no format', u'1', TypeError, 
+         "not all arguments converted during string formatting")
 
 if sys.maxint == 2**32-1:
     # crashes 2.2.1 and earlier:
index 35b4b47e986438ccf6f81919a3cd9e1f2ed5ded7..bf8bad53a83c86f5af8fe87f274615689a9e3be6 100644 (file)
@@ -3622,7 +3622,8 @@ PyString_Format(PyObject *format, PyObject *args)
                arglen = -1;
                argidx = -2;
        }
-       if (args->ob_type->tp_as_mapping && !PyTuple_Check(args))
+       if (args->ob_type->tp_as_mapping && !PyTuple_Check(args) &&
+           !PyObject_TypeCheck(args, &PyBaseString_Type))
                dict = args;
        while (--fmtcnt >= 0) {
                if (*fmt != '%') {
index c1cdebc0e8e9e10b00a5120b05c21eb6f9951af5..12846bf49b8c08f0c3410bd295cfa6407ebe8c0a 100644 (file)
@@ -6181,7 +6181,8 @@ PyObject *PyUnicode_Format(PyObject *format,
        arglen = -1;
        argidx = -2;
     }
-    if (args->ob_type->tp_as_mapping && !PyTuple_Check(args))
+    if (args->ob_type->tp_as_mapping && !PyTuple_Check(args) &&
+        !PyObject_TypeCheck(args, &PyBaseString_Type))
        dict = args;
 
     while (--fmtcnt >= 0) {