Fix comparison type deduction.
authorRobert Bradshaw <robertwb@math.washington.edu>
Thu, 22 Oct 2009 05:34:50 +0000 (22:34 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Thu, 22 Oct 2009 05:34:50 +0000 (22:34 -0700)
Cython/Compiler/ExprNodes.py
tests/run/cmp.pyx

index 8ec30f9fc42b9a74eebc0c3dc2a1b0091ff2b3da..5a532955a5d8991026153f8fc37e952967b150ae 100644 (file)
@@ -5132,9 +5132,11 @@ class CmpNode(object):
 
         if new_common_type is None:
             # fall back to generic type compatibility tests
-            if type1 == type2 or type1.assignable_from(type2):
+            if type1 == type2:
                 new_common_type = type1
-            elif type2.assignable_from(type1):
+            elif not type2 is py_object_type and type1.assignable_from(type2):
+                new_common_type = type1
+            elif not type1 is py_object_type and type2.assignable_from(type1):
                 new_common_type = type2
             elif type1.is_pyobject and type2.is_pyobject:
                 new_common_type = py_object_type
index 7cb9c05edbf0fd0fe9bc137ece93a635d698751b..0cffec98f387000a78cfbad9ffad4f47a233dbd3 100644 (file)
@@ -33,3 +33,10 @@ def single_c(int a, int b):
 
 def cascaded_c(double a, double b, double c):
     return a < b < c
+
+def typed_cmp(list L):
+    """
+    >>> typed_cmp([1,2,3])
+    (False, False)
+    """
+    return L is Ellipsis, Ellipsis is L