diff options
-rw-r--r-- | Lib/test/test_format.py | 8 | ||||
-rw-r--r-- | Objects/stringobject.c | 3 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 3 |
3 files changed, 12 insertions, 2 deletions
diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py index b40e820..da4d85a 100644 --- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -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: diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 35b4b47..bf8bad5 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -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 != '%') { diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index c1cdebc..12846bf 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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) { |