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

Jelte Fennema me at jeltef.nl
Mon Nov 23 14:09:17 EST 2015


Hi,

After reading PEP0465 <https://www.python.org/dev/peps/pep-0465/> 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
<https://www.python.org/dev/peps/pep-0335/> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151123/8b802217/attachment.html>


More information about the Python-ideas mailing list