[Python-ideas] [Python-ideos] Dedicated overloadable boolean operators

Random832 random832 at fastmail.com
Tue Nov 24 14:07:35 EST 2015


On 2015-11-24, Brendan Barnwell wrote:
> 	The problem is that this kind of overriding doesn't handle the main use
> case, which is elementwise and-ing/or-ing.  If a is some numpy-like
> array of [1, 1], then it may be boolean true, but you still want "a
> magic_or b" to do the elementwise operation, not just return "a" by
> itself.

Why? I am asking specifically because *all* elements of a are true, so all
elements of the result will also be true, and taken from a. Clearly [0, 1]
should *not* return true for a.__true__(), which is why I didn't use __bool__.
But the elementwise operation [1, 1] magic_or [0, 2] returns [1, 1].



More information about the Python-ideas mailing list