x = FixedPoint("1.1")
print x == None
produces an exception, rather than returning False.
According to the docs:
"The operators <, >, ==, >=, <=, and != compare
the values of two objects. The objects need not
have the same type. If both are numbers, they are
converted to a common type. Otherwise, objects of
different types always compare unequal, and are
ordered consistently but arbitrarily."
For FixedPoint this should perhaps read "If both or
numbers or strings that can be parsed by FixedPoint.
..." -- otherwise it seems more logical that the
above snippet should return False, not raise an
exception (integers work that way).
Logged In: YES
user_id=693152
I have also encountered this behaviour. I would classify it
as buggy (standard function does not behave as expected), or
at the very least unhelpful.
I've modified the __cmp__ function. Since I don't have the
option to upload a patch file, I'll just reproduce the
entire function below:
def __cmp__(self, other):
try:
xn, yn, p = _norm(self, other,
FixedPoint=type(self))
except TypeError:
# Could not convert other into a FixedPoint.
# Instead, we do a comparison with the number
# (in order to get consistent comparisons, as
# expected for this function)
return cmp(self.n, other)
return cmp(xn, yn)