From da1acf30545d72207759ac3ecb79fe0aa0201961 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 31 Oct 2009 15:35:48 +0100 Subject: [PATCH] fix C assignment issue for the typed target case --- Cython/Compiler/Optimize.py | 6 ++++-- tests/run/tp_new.pyx | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index 44a9cda0..c8258ef4 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -756,7 +756,9 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform): ### cleanup to avoid redundant coercions to/from Python types - def visit_PyTypeTestNode(self, node): + def _visit_PyTypeTestNode(self, node): + # disabled - appears to break assignments in some cases, and + # also drops a None check, which might still be required """Flatten redundant type checks after tree changes. """ old_arg = node.arg @@ -1073,7 +1075,7 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform): # of the extension type and call that instead of the generic slot func_type = PyrexTypes.CFuncType( return_type, [ - PyrexTypes.CFuncTypeArg("type", PyrexTypes.py_object_type, None) + PyrexTypes.CFuncTypeArg("type", Builtin.type_type, None) ]) if not type_arg.type_entry: diff --git a/tests/run/tp_new.pyx b/tests/run/tp_new.pyx index d176fc3b..01f06827 100644 --- a/tests/run/tp_new.pyx +++ b/tests/run/tp_new.pyx @@ -29,6 +29,17 @@ def make_new(): m = MyType.__new__(MyType) return m +@cython.test_assert_path_exists('//PythonCapiCallNode') +@cython.test_fail_if_path_exists('//SimpleCallNode/AttributeNode') +def make_new_typed_target(): + """ + >>> isinstance(make_new_typed_target(), MyType) + True + """ + cdef MyType m + m = MyType.__new__(MyType) + return m + @cython.test_assert_path_exists('//PythonCapiCallNode') @cython.test_fail_if_path_exists('//SimpleCallNode/AttributeNode') def make_new_builtin(): -- 2.26.2