#('round', "", "", ""),
('setattr', "OOO", "r", "PyObject_SetAttr"),
#('sum', "", "", ""),
- ('type', "O", "O", "PyObject_Type"),
+ #('type', "O", "O", "PyObject_Type"),
#('unichr', "", "", ""),
#('unicode', "", "", ""),
#('vars', "", "", ""),
func_type.opt_arg_cname(formal_arg.name),
actual_arg.result_as(formal_arg.type)))
exc_checks = []
- if self.type.is_pyobject:
+ if self.type.is_pyobject and self.is_temp:
exc_checks.append("!%s" % self.result())
else:
exc_val = func_type.exception_value
return replace_in(arg)
return node
- Pyx_Type_func_type = PyrexTypes.CFuncType(
- Builtin.type_type, [
- PyrexTypes.CFuncTypeArg("object", PyrexTypes.py_object_type, None)
- ])
-
- def _handle_simple_function_type(self, node, pos_args):
- if len(pos_args) != 1:
- return node
- self._inject_capi_function(
- node, "__Pyx_Type",
- self.Pyx_Type_func_type,
- pytype_utility_code)
- return node
-
def _handle_simple_function_float(self, node, pos_args):
if len(pos_args) == 0:
return ExprNodes.FloatNode(node.pos, value='0.0')
)
return node
+ Pyx_Type_func_type = PyrexTypes.CFuncType(
+ Builtin.type_type, [
+ PyrexTypes.CFuncTypeArg("object", PyrexTypes.py_object_type, None)
+ ])
+
+ def _handle_simple_function_type(self, node, pos_args):
+ if len(pos_args) != 1:
+ return node
+ node = ExprNodes.PythonCapiCallNode(
+ node.pos, "Py_TYPE", self.Pyx_Type_func_type,
+ args = pos_args,
+ is_temp = False)
+ return ExprNodes.CastNode(node, PyrexTypes.py_object_type)
+
### special methods
Pyx_tp_new_func_type = PyrexTypes.CFuncType(
)
-pytype_utility_code = UtilityCode(
-proto = """
-static INLINE PyObject* __Pyx_Type(PyObject* o) {
- PyObject* type = (PyObject*) Py_TYPE(o);
- Py_INCREF(type);
- return type;
-}
-"""
-)
-
-
include_string_h_utility_code = UtilityCode(
proto = """
#include <string.h>
--- /dev/null
+cimport cython
+
+@cython.test_assert_path_exists(
+ '//PythonCapiCallNode/PythonCapiFunctionNode[@cname="Py_TYPE"]')
+def get_type_of(a):
+ """
+ >>> get_type_of(object()) is object
+ True
+ """
+ return type(a)
+
+@cython.test_assert_path_exists(
+ '//PythonCapiCallNode/PythonCapiFunctionNode[@cname="Py_TYPE"]')
+def get_type_through_local(a):
+ """
+ >>> get_type_of(object()) is object
+ True
+ """
+ t = type(a)
+ return t
+
+@cython.test_assert_path_exists(
+ '//PythonCapiCallNode/PythonCapiFunctionNode[@cname="Py_TYPE"]')
+@cython.test_fail_if_path_exists(
+ '//PythonCapiCallNode/PythonCapiFunctionNode[@cname="__Pyx_Type"]',
+ '//NameNode[@name="type"]')
+def test_type(a, t):
+ """
+ >>> test_type(object(), object)
+ True
+ """
+ return type(a) and type(a) is t and type(a) == t
+
+@cython.test_assert_path_exists('//NameNode[@name="type"]')
+def type_type():
+ """
+ >>> type_type()(object()) is object
+ True
+ """
+ return type