summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2008-02-18 18:02:34 (GMT)
committerEric Smith <eric@trueblade.com>2008-02-18 18:02:34 (GMT)
commitbc32fee0291cc8ff4085ad805c0f4dca97345863 (patch)
treea56815ec19a76df767a34f225de50ac00a45486e /Objects
parent5299935be5acefae819bcc08a888a9466747d7cb (diff)
downloadcpython-bc32fee0291cc8ff4085ad805c0f4dca97345863.zip
cpython-bc32fee0291cc8ff4085ad805c0f4dca97345863.tar.gz
cpython-bc32fee0291cc8ff4085ad805c0f4dca97345863.tar.bz2
Added code to correct combining str and unicode in ''.format(). Added test case.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/stringlib/string_format.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/Objects/stringlib/string_format.h b/Objects/stringlib/string_format.h
index 70f8f13..e776242 100644
--- a/Objects/stringlib/string_format.h
+++ b/Objects/stringlib/string_format.h
@@ -493,6 +493,22 @@ render_field(PyObject *fieldobj, SubString *format_spec, OutputString *output)
if (result == NULL)
goto done;
+#if PY_VERSION_HEX >= 0x03000000
+ assert(PyString_Check(result));
+#else
+ assert(PyString_Check(result) || PyUnicode_Check(result));
+
+ /* Convert result to our type. We could be str, and result could
+ be unicode */
+ {
+ PyObject *tmp = STRINGLIB_TOSTR(result);
+ if (tmp == NULL)
+ goto done;
+ Py_DECREF(result);
+ result = tmp;
+ }
+#endif
+
ok = output_data(output,
STRINGLIB_STR(result), STRINGLIB_LEN(result));
done: