Commit ac6b858e authored by Stefan Behnel's avatar Stefan Behnel

Prevent UnicodeEncodeError in Py2 when ``%s`` formatting is optimised for unicode strings.

parent eb0e4666
......@@ -13,6 +13,9 @@ Bugs fixed
* Overriding cpdef methods did not work in Python subclasses with slots.
(Github issue #1771)
* ``UnicodeEncodeError`` in Py2 when ``%s`` formatting is optimised for
unicode strings.
0.28.2 (2018-04-13)
===================
......
......@@ -3164,7 +3164,7 @@ class FormattedValueNode(ExprNode):
c_format_spec = None
find_conversion_func = {
's': 'PyObject_Str',
's': 'PyObject_Unicode',
'r': 'PyObject_Repr',
'a': 'PyObject_ASCII', # NOTE: mapped to PyObject_Repr() in Py2
}.get
......
......@@ -558,6 +558,7 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
#define PyString_Type PyUnicode_Type
#define PyString_Check PyUnicode_Check
#define PyString_CheckExact PyUnicode_CheckExact
#define PyObject_Unicode PyObject_Str
#endif
#if PY_MAJOR_VERSION >= 3
......
......@@ -500,3 +500,16 @@ def generated_fstring(int i, unicode u not None, o):
u, u, u, u,
o, o, o, o,
)
@cython.test_assert_path_exists(
"//FormattedValueNode",
"//AddNode",
)
def percent_s_unicode(u, int i):
u"""
>>> u = u'x\u0194z'
>>> print(percent_s_unicode(u, 12))
x\u0194z-12
"""
return u"%s-%d" % (u, i)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment