self.operand1.result(),
self.operand2.result())
+ def is_py_operation_types(self, type1, type2):
+ return (type1 is PyrexTypes.c_py_unicode_type or
+ type2 is PyrexTypes.c_py_unicode_type or
+ BinopNode.is_py_operation_types(self, type1, type2))
+
def py_operation_function(self):
return self.py_functions[self.operator]
return type1
elif type1 is py_object_type or type2 is py_object_type:
return py_object_type
+ elif type1 is c_py_unicode_type or type2 is c_py_unicode_type:
+ # Py_UNICODE behaves more like a string than an int
+ return py_object_type
span_type = _spanning_type(type1, type2)
if span_type is None:
return py_object_type
IndexError: string index out of range
"""
return ustring[i] == other
+
+@cython.test_assert_path_exists("//CoerceToPyTypeNode",
+ "//IndexNode",
+ "//MulNode",
+ "//MulNode/CoerceToPyTypeNode")
+@cython.test_fail_if_path_exists("//IndexNode//CoerceToPyTypeNode")
+def index_multiply(unicode ustring, Py_ssize_t i, int mul):
+ """
+ >>> ustring[0] * 5
+ u'aaaaa'
+ >>> index_multiply(ustring, 0, 5)
+ u'aaaaa'
+ """
+ return ustring[i] * mul
+
+@cython.test_assert_path_exists("//CoerceToPyTypeNode",
+ "//IndexNode",
+ "//AddNode",
+ "//AddNode/CoerceToPyTypeNode")
+@cython.test_fail_if_path_exists("//IndexNode//CoerceToPyTypeNode")
+def index_add(unicode ustring, Py_ssize_t i, Py_ssize_t j):
+ """
+ >>> ustring[0] + ustring[-1]
+ u'a6'
+ >>> index_add(ustring, 0, -1)
+ u'a6'
+ """
+ return ustring[i] + ustring[j]