Commit 72f826ca authored by Stefan Behnel's avatar Stefan Behnel

fix rich eq/ne comparisons with string literals if they return non-boolean values

parent a3ace265
...@@ -8723,7 +8723,7 @@ class CmpNode(object): ...@@ -8723,7 +8723,7 @@ class CmpNode(object):
# note: currently operand1 must get coerced to a Python object if we succeed here! # note: currently operand1 must get coerced to a Python object if we succeed here!
if self.operator in ('==', '!='): if self.operator in ('==', '!='):
type1, type2 = operand1.type, self.operand2.type type1, type2 = operand1.type, self.operand2.type
if type1.is_pyobject and type2.is_pyobject: if type1.is_builtin_type and type2.is_builtin_type:
if type1 is Builtin.unicode_type or type2 is Builtin.unicode_type: if type1 is Builtin.unicode_type or type2 is Builtin.unicode_type:
self.special_bool_cmp_utility_code = UtilityCode.load_cached("UnicodeEquals", "StringTools.c") self.special_bool_cmp_utility_code = UtilityCode.load_cached("UnicodeEquals", "StringTools.c")
self.special_bool_cmp_function = "__Pyx_PyUnicode_Equals" self.special_bool_cmp_function = "__Pyx_PyUnicode_Equals"
......
# mode: run
class plop(object):
def __init__(self):
pass
class testobj(object):
def __init__(self):
pass
def __eq__(self, other):
return plop()
def test_equals():
"""
>>> result = test_equals()
>>> isinstance(result, plop)
True
"""
blah = testobj()
eq = blah == 'coucou' # not every str equals returns a bool ...
return eq
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment