9950865c39
These are now returned as "operation not supported" instead of raising TypeError. In particular, this fixes equality for float vs incompatible types, which now properly results in False instead of exception. This also paves the road to support reverse operation (e.g. __radd__) with float objects. This is achieved by introducing mp_obj_get_float_maybe(), similar to existing mp_obj_get_int_maybe().
23 lines
288 B
Python
23 lines
288 B
Python
# Extended float comparisons
|
|
|
|
class Foo:
|
|
pass
|
|
|
|
foo = Foo()
|
|
|
|
print(foo == 1.0)
|
|
print(1.0 == foo)
|
|
print(1.0 == Foo)
|
|
print(1.0 == [])
|
|
print(1.0 == {})
|
|
|
|
try:
|
|
print(foo < 1.0)
|
|
except TypeError:
|
|
print("TypeError")
|
|
|
|
try:
|
|
print(1.0 < foo)
|
|
except TypeError:
|
|
print("TypeError")
|