fix ticket #644: infer type of C-API optimised methods of builtin types as Python...
authorStefan Behnel <scoder@users.berlios.de>
Thu, 13 Jan 2011 16:12:55 +0000 (17:12 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Thu, 13 Jan 2011 16:12:55 +0000 (17:12 +0100)
Cython/Compiler/ExprNodes.py
tests/run/type_inference.pyx

index 688a5091722b4bf72511d1a498814cb59707f076..93eba7cc2eb07e4583e5926cfdeccfaba01e35c8 100755 (executable)
@@ -3356,7 +3356,14 @@ class AttributeNode(ExprNode):
         elif self.analyse_as_unbound_cmethod(env):
             return self.entry.type
         else:
-            self.analyse_attribute(env, obj_type = self.obj.infer_type(env))
+            obj_type = self.obj.infer_type(env)
+            self.analyse_attribute(env, obj_type = obj_type)
+            if obj_type.is_builtin_type and self.type.is_cfunction:
+                # special case: C-API replacements for C methods of
+                # builtin types cannot be inferred as C functions as
+                # that would prevent their use as bound methods
+                self.type = py_object_type
+                return py_object_type
             return self.type
 
     def analyse_target_declaration(self, env):
index 74e1449096135cf8fd4d1e014e9aa66617b5aafb..e36e43baa160b93233e4e41433a9d4f7c97faf14 100644 (file)
@@ -199,6 +199,15 @@ def builtin_type_operations():
     T2 = () * 2
     assert typeof(T2) == "tuple object", typeof(T2)
 
+def builtin_type_methods():
+    """
+    >>> builtin_type_methods()
+    """
+    l = []
+    assert typeof(l) == 'list object', typeof(l)
+    append = l.append
+    assert typeof(append) == 'Python object', typeof(append)
+
 cdef int func(int x):
     return x+1