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

Emanuel Barry vgr255 at live.ca
Mon Nov 23 15:22:53 EST 2015


Could you provide some links to where this could be useful, and how code could be rewritten? I can see the desire for such a feature, I myself would have liked such an operator or keyword. If you get general approval on this list, you can then move on to write a PEP (as that's what's needed if you wish to add a new keyword and/or operator to the language).
I'm +0 for now, and may change once you provide us with use cases in the wild.-Emanuel
From: me at jeltef.nl
Date: Mon, 23 Nov 2015 20:09:17 +0100
To: python-ideas at python.org
Subject: [Python-ideas] [Python-ideos] Dedicated overloadable boolean operators

Hi,
After reading PEP0465 about the dedicated matrix multiplication I started wondering if the same solution couldn't be applied to boolean operators as well. There currently are a lot of high profile libraries that have their own functions for boolean operators, like Numpy, Pandas or SQLAlchemy. They do this because the current boolean operators can't be overloaded. PEP0335 was created to solve this problem (and makes the problem more clear), but was rejected because it needed changes to the byte code for the boolean operators, which would make them slower. Currently some of these libraries resort to the bitwise operators (at least Pandas), but those don't bind as strong as comparison operators, which means you have to do comparisons like this: (series1 == 2) & (series2 == 3) 
That is why I propose to create new operators just like for matrix multiplication which can be used in libraries that need one. I'm not sure what the operators should look like, but my first guess would be &&, || and ! for and, or and not respectively. 
Is this an idea that sounds reasonable?
Jelte

_______________________________________________
Python-ideas mailing list
Python-ideas at python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/ 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151123/49533ef4/attachment.html>


More information about the Python-ideas mailing list