diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-09-02 21:19:01 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-09-02 23:05:24 +0300 |
commit | 9950865c39044e9fef295d0676af7c5fd55289ea (patch) | |
tree | 38a31f618de5b880ca4024ec1ed4c0e965e41aa5 /tests/float/float_compare.py | |
parent | dd376a239dc4f47b0ee7866810fcda151f3cf6dd (diff) | |
download | micropython-9950865c39044e9fef295d0676af7c5fd55289ea.tar.gz micropython-9950865c39044e9fef295d0676af7c5fd55289ea.zip |
py/objfloat: Fix binary ops with incompatible objects.
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().
Diffstat (limited to 'tests/float/float_compare.py')
-rw-r--r-- | tests/float/float_compare.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/float/float_compare.py b/tests/float/float_compare.py new file mode 100644 index 0000000000..105923ac73 --- /dev/null +++ b/tests/float/float_compare.py @@ -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") |