Without invoking double-underscore black magic, it is possible to
choose a, b, and c in Python such that:
a < b
b < c
c < a
This could cause sorting functions to malfunction.
[color=blue][color=green][color=darkred]
>>> class t(object):[/color][/color][/color]
.... pass
....[color=blue][color=green][color=darkred]
>>> a = t()
>>> b = u'0'
>>> c = '1'
>>> a < b[/color][/color][/color]
True[color=blue][color=green][color=darkred]
>>> b < c[/color][/color][/color]
True[color=blue][color=green][color=darkred]
>>> c < a[/color][/color][/color]
True
Possible kludge fix: Change default_3way_co mpare() to use "basestring "
as the typename for both built-in string types.
Possible elegant fix: Any class whose members may either be less than
or greater than members of a different class, which often share a
common superclass, use the name of the superclass for comparisons with
objects of incompatible types. This parallels the comparison of
numeric types because they compare as if their type name were empty.
choose a, b, and c in Python such that:
a < b
b < c
c < a
This could cause sorting functions to malfunction.
[color=blue][color=green][color=darkred]
>>> class t(object):[/color][/color][/color]
.... pass
....[color=blue][color=green][color=darkred]
>>> a = t()
>>> b = u'0'
>>> c = '1'
>>> a < b[/color][/color][/color]
True[color=blue][color=green][color=darkred]
>>> b < c[/color][/color][/color]
True[color=blue][color=green][color=darkred]
>>> c < a[/color][/color][/color]
True
Possible kludge fix: Change default_3way_co mpare() to use "basestring "
as the typename for both built-in string types.
Possible elegant fix: Any class whose members may either be less than
or greater than members of a different class, which often share a
common superclass, use the name of the superclass for comparisons with
objects of incompatible types. This parallels the comparison of
numeric types because they compare as if their type name were empty.
Comment