From 3c0c4d0648496a7c58bbb74de5891a85820cda36 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 21 Oct 2009 22:34:50 -0700 Subject: [PATCH] Fix comparison type deduction. --- Cython/Compiler/ExprNodes.py | 6 ++++-- tests/run/cmp.pyx | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 8ec30f9f..5a532955 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -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 diff --git a/tests/run/cmp.pyx b/tests/run/cmp.pyx index 7cb9c05e..0cffec98 100644 --- a/tests/run/cmp.pyx +++ b/tests/run/cmp.pyx @@ -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 -- 2.26.2