So I have a one liner:
import decimal; h = decimal.Decimal('100.0'); (h > .01, h < .01, h.__gt__(.01), h.__lt__(.01))
All it does is make a Decimal object holding 100.0, and compares it to .01 (the float) in various ways.
My result is:
>>> import decimal; h = decimal.Decimal('100.0'); (h > .01, h < .01, h.__gt__(.01), h.__lt__(.01))
(False, True, NotImplemented, NotImplemented)
From the docs: "A rich comparison method may return the singleton NotImplemented if it does not implement the operation for a given pair of arguments."
So really there are three questions here.
When a rich comparison method returns NotImplemented, what happens? Why doesn't it raise an Exception?
When it gets NotImplemented, why does it return False in the first case, and True in the second? bool(NotImplemented) should be a constant.
Does it simply fall back to id() checking? It seems no (or yes, but backwards):
(ignore this line, formatting is screwed up and this fixes it)
from decimal import Decimal
h = Decimal('100.0')
f = .01
print h < f, id(h) < id(f)
print h > f, id(h) > id(f)
My results were tested on:
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32
Edit: Documentation about ordering: http://docs.python.org/library/stdtypes.html#comparisons