("bytes", "PyBytes_Type", []),
("str", "PyString_Type", []),
- ("unicode", "PyUnicode_Type", []),
+ ("unicode", "PyUnicode_Type", [("join", "TO", "T", "PyUnicode_Join"),
+ ]),
("tuple", "PyTuple_Type", []),
("dict", "PyDict_Type", [("items", "T", "O", "PyDict_Items"),
("keys", "T", "O", "PyDict_Keys"),
("values","T", "O", "PyDict_Values"),
- ("copy", "T", "O", "PyDict_Copy")]),
+ ("copy", "T", "T", "PyDict_Copy")]),
("slice", "PySlice_Type", []),
# ("file", "PyFile_Type", []), # not in Py3
node, "PyUnicode_Splitlines", self.PyUnicode_Splitlines_func_type,
'splitlines', is_unbound_method, args)
- PyUnicode_Join_func_type = PyrexTypes.CFuncType(
- Builtin.unicode_type, [
- PyrexTypes.CFuncTypeArg("sep", Builtin.unicode_type, None),
- PyrexTypes.CFuncTypeArg("iterable", PyrexTypes.py_object_type, None),
- ])
-
- def _handle_simple_method_unicode_join(self, node, args, is_unbound_method):
- """Replace unicode.join(...) by a direct call to the
- corresponding C-API function.
- """
- if len(args) != 2:
- self._error_wrong_arg_count('unicode.join', node, args, 2)
- return node
-
- return self._substitute_method_call(
- node, "PyUnicode_Join", self.PyUnicode_Join_func_type,
- 'join', is_unbound_method, args)
-
PyUnicode_Split_func_type = PyrexTypes.CFuncType(
Builtin.list_type, [
PyrexTypes.CFuncTypeArg("str", Builtin.unicode_type, None),
error_value_map = {
'O': "NULL",
+ 'T': "NULL",
'i': "-1",
'b': "-1",
'l': "-1",
# argument is 'self' for methods or 'class' for classmethods
return self.fixed_arg_format[i] == 'T'
+ def returns_self_type(self):
+ # return type is same as 'self' argument type
+ return self.ret_format == 'T'
+
def fixed_arg_type(self, i):
return self.format_map[self.fixed_arg_format[i]]
else:
arg_type = self.fixed_arg_type(i)
args.append(PyrexTypes.CFuncTypeArg("", arg_type, None))
- ret_type = self.return_type()
+ if self_arg_override is not None and self.returns_self_type():
+ ret_type = self_arg_override.type
+ else:
+ ret_type = self.return_type()
exc_value = self.exception_value()
return PyrexTypes.CFuncType(ret_type, args, exception_value = exc_value)
@cython.test_fail_if_path_exists(
"//CoerceToPyTypeNode", "//CoerceFromPyTypeNode",
- "//CastNode", "//TypecastNode")
+ "//CastNode", "//TypecastNode",
+ "//SimpleCallNode//AttributeNode[@is_py_attr = true]")
@cython.test_assert_path_exists(
- "//PythonCapiCallNode")
+ "//SimpleCallNode",
+ "//SimpleCallNode//NoneCheckNode",
+ "//SimpleCallNode//AttributeNode[@is_py_attr = false]")
def join(unicode sep, l):
"""
>>> l = text.split()
@cython.test_fail_if_path_exists(
"//CoerceToPyTypeNode", "//CoerceFromPyTypeNode",
- "//CastNode", "//TypecastNode", "//NoneCheckNode")
+ "//CastNode", "//TypecastNode", "//NoneCheckNode",
+ "//SimpleCallNode//AttributeNode[@is_py_attr = true]")
@cython.test_assert_path_exists(
- "//PythonCapiCallNode")
+ "//SimpleCallNode",
+ "//SimpleCallNode//AttributeNode[@is_py_attr = false]")
def join_sep(l):
"""
>>> l = text.split()