[Python-ideas] Revisiting dedicated overloadable boolean operators
MRAB
python at mrabarnett.plus.com
Fri Aug 3 21:17:44 EDT 2018
On 2018-08-03 23:05, Benedikt Werner wrote:
>> There was a proposal to allow overloading boolean operators in Pep-335
>> [2], but that PEP was rejected for a variety of very good reasons. I
>> think none of those reasons (besides the conversation fizzling out)
>> apply to my proposal.
> Maybe I am missing something, but I don't really see how this idea
> solves the problems that lead to PEP 335 getting rejected. As far as I
> understand it the main reason for the rejection was that this would
> decrease performance for all boolean operations which are extremely
> common where as the need for overriding these operators is rather rare.
> (See the rejection email here:
> https://mail.python.org/pipermail/python-dev/2012-March/117510.html)
>
> As I see it this proposal only proposes a different syntax and doesn't
> solve this problem.
>
[snip]
I've been re-reading PEP 335 and I think that the __and1__ method isn't
needed.
The __bool__ method is called anyway, and currently must return either
False or True, but what if it could return the special value
NeedOtherOperand mentioned in the PEP?
The disadvantage would be that if the first operand is a bool, the
operator could still short-circuit, and I'm not sure how much of an
issue that would be.
More information about the Python-ideas
mailing list