From 8d79bfe0cf4b69689128b231d5186204314b7aad Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Sat, 15 Jun 2013 21:54:23 -0700 Subject: [PATCH] Perform typecheck for (typechecking) builtin casts. --- Cython/Compiler/ExprNodes.py | 3 ++- tests/run/typetest_T417.pyx | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index bc8cb0e..f47ce3b 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -8022,6 +8022,7 @@ class TypecastNode(ExprNode): # operand ExprNode # base_type CBaseTypeNode # declarator CDeclaratorNode + # typecheck boolean # # If used from a transform, one can if wanted specify the attribute # "type" directly and leave base_type and declarator to None @@ -8082,7 +8083,7 @@ class TypecastNode(ExprNode): else: warning(self.pos, "No conversion from %s to %s, python object pointer used." % (self.type, self.operand.type)) elif from_py and to_py: - if self.typecheck and self.type.is_extension_type: + if self.typecheck and self.type.is_pyobject: self.operand = PyTypeTestNode(self.operand, self.type, env, notnone=True) elif isinstance(self.operand, SliceIndexNode): # This cast can influence the created type of string slices. diff --git a/tests/run/typetest_T417.pyx b/tests/run/typetest_T417.pyx index bca35b1..7d7b249 100644 --- a/tests/run/typetest_T417.pyx +++ b/tests/run/typetest_T417.pyx @@ -101,3 +101,14 @@ def test_getFooCast(): cdef int old_count = count cdef Foo x = getFoo() return count - old_count + +def test_builtin_typecheck_cast(maybe_list): + """ + >>> test_builtin_typecheck_cast([]) + [] + >>> test_builtin_typecheck_cast({}) + Traceback (most recent call last): + ... + TypeError: Expected list, got dict + """ + return maybe_list -- 2.7.4