[issue1997] unicode and string compare should not cause an exception

Marc-Andre Lemburg report at bugs.python.org
Fri Feb 1 22:38:13 CET 2008


Marc-Andre Lemburg added the comment:

The change we did was for == and != comparisons to always work (they now
"raise" warnings) - mostly because doing otherwise resulted in strange
exceptions when dealing with dictionary lookups. 

However, this was not done for comparisons <, <=, >=, > since these test
for ordering and it's not at all clear what the default outcome should be.

>>> u'abc' == 'äöü'
UnicodeWarning: Unicode equal comparison failed to convert both
arguments to Unicode - interpreting them as being unequal
False

>>> u'abc' < 'äöü'
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0:
ordinal not in range(128)

>>> 1 < 1j
TypeError: no ordering relation is defined for complex numbers

----------
nosy: +lemburg

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1997>
__________________________________


More information about the Python-bugs-list mailing list