[Python-ideas] Revisiting dedicated overloadable boolean operators

Benedikt Werner 1benediktwerner at gmail.com
Fri Aug 3 18:05:46 EDT 2018


> 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.

The only real solution for this would be a new set of operators but I 
agree with Chris that overriding the bitwise operators is good enough 
for most cases and a new set of operators really is a bit over the top 
just for this. I especially dislike using || and && as they are 
prominently used in other programming languages and this would be 
extremely confusing for newcomers from those languages. Also if the 
syntax isn't clear and consice I feel it doesn't really add any value as 
the main point of operator overloading is to make code easy to read and 
understand. This really only would be the case if we could overload the 
boolean operators. Otherweise I think using a function or overloading 
the bitwise ops is the best solution.



More information about the Python-ideas mailing list