Commit d0d36736 authored by da-woods's avatar da-woods Committed by GitHub

Only use PyUnicode_Concat on unicode object operations (GH-3433)

parent eab4e09a
......@@ -11364,19 +11364,24 @@ class AddNode(NumBinopNode):
self, type1, type2)
def py_operation_function(self, code):
is_unicode_concat = False
if isinstance(self.operand1, FormattedValueNode) or isinstance(self.operand2, FormattedValueNode):
is_unicode_concat = True
else:
type1, type2 = self.operand1.type, self.operand2.type
if type1 is unicode_type or type2 is unicode_type:
is_unicode_concat = type1.is_builtin_type and type2.is_builtin_type
type1, type2 = self.operand1.type, self.operand2.type
if is_unicode_concat:
if self.operand1.may_be_none() or self.operand2.may_be_none():
return '__Pyx_PyUnicode_ConcatSafe'
if type1 is unicode_type or type2 is unicode_type:
if type1 in (unicode_type, str_type) and type2 in (unicode_type, str_type):
is_unicode_concat = True
elif isinstance(self.operand1, FormattedValueNode) or isinstance(self.operand2, FormattedValueNode):
# Assume that even if we don't know the second type, it's going to be a string.
is_unicode_concat = True
else:
return '__Pyx_PyUnicode_Concat'
# Operation depends on the second type.
is_unicode_concat = False
if is_unicode_concat:
if self.operand1.may_be_none() or self.operand2.may_be_none():
return '__Pyx_PyUnicode_ConcatSafe'
else:
return '__Pyx_PyUnicode_Concat'
return super(AddNode, self).py_operation_function(code)
......
......@@ -993,6 +993,14 @@ class CommonTest(BaseTest):
self.checkequal('\u019b\u1d00\u1d86\u0221\u1fb7',
'\u019b\u1d00\u1d86\u0221\u1fb7', 'capitalize')
def test_list_concat(self):
# https://github.com/cython/cython/issues/3426
y = []
y += 'ab'
self.assertEqual('a', y[0])
self.assertEqual('b', y[1])
self.assertEqual(['a', 'b'], y)
class MixinStrUnicodeUserStringTest:
# additional tests that only work for
......
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