keep type information when coercing from C complex to Python complex
authorStefan Behnel <scoder@users.berlios.de>
Sat, 4 Dec 2010 06:49:57 +0000 (07:49 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Sat, 4 Dec 2010 06:49:57 +0000 (07:49 +0100)
Cython/Compiler/ExprNodes.py

index d721a69ef06c06575e2d8199a2fd3851f20bf840..d58e9823e7c01cc17970a5a1332e388625ef17b8 100755 (executable)
@@ -7074,12 +7074,17 @@ class CoerceToPyTypeNode(CoercionNode):
         if not arg.type.create_to_py_utility_code(env):
             error(arg.pos,
                   "Cannot convert '%s' to Python object" % arg.type)
-        if type is not py_object_type:
-            self.type = py_object_type
-        elif arg.type.is_string:
-            self.type = bytes_type
-        elif arg.type is PyrexTypes.c_py_unicode_type:
-            self.type = unicode_type
+        if type is py_object_type:
+            # be specific about some known types
+            if arg.type.is_string:
+                self.type = bytes_type
+            elif arg.type is PyrexTypes.c_py_unicode_type:
+                self.type = unicode_type
+            elif arg.type.is_complex:
+                self.type = Builtin.complex_type
+        else:
+            # FIXME: check that the target type and the resulting type are compatible
+            pass
 
     gil_message = "Converting to Python object"