[Python-ideas] [Python-ideos] Dedicated overloadable boolean operators
Brendan Barnwell
brenbarn at brenbarn.net
Tue Nov 24 14:27:51 EST 2015
On 2015-11-24 11:07, Random832 wrote:
> 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].
I guess I'm not understanding what you mean by __true__ then. What is
this __true__ for which ([0, 1]).__true__() is not true?
--
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no
path, and leave a trail."
--author unknown
More information about the Python-ideas
mailing list