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().crypto-aes
parent
dd376a239d
commit
9950865c39
@ -0,0 +1,22 @@
|
||||
# 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")
|
Loading…
Reference in new issue