larray-project / larray

N-dimensional labelled arrays in Python
https://larray.readthedocs.io/
GNU General Public License v3.0
8 stars 6 forks source link

binops between Array and "unknown" types should not always return False #1064

Closed gdementen closed 1 year ago

gdementen commented 1 year ago

The return False behavior should only be for == (and True for !=). Related to #988.

>>> object() == object()
False
>>> object() != object()
True

This can be very confusing in some cases, especially for !=:

>>> ndtest(10) != object()
False
>>> ndtest(10) > object()
False
>>> ndtest(10) < object()
False
>>> ndtest(10) + object()
False

Usually comparison operators return TypeError in that case:

>>> object() > object()
TypeError: '>' not supported between instances of 'object' and 'object'

Other arithmetic operations also return TypeError:

>>> object() + object()
TypeError: unsupported operand type(s) for +: 'object' and 'object'

As far as I am concerned, I would use the same message for both cases.