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

Nathaniel Smith njs at pobox.com
Tue Nov 24 14:37:41 EST 2015


On Nov 24, 2015 10:21 AM, "Guido van Rossum" <guido at python.org> wrote:
>
> To everyone claiming that you can't overload and/or because they are
> shortcut operators, please re-read PEP 335. It provides a clean
> solution -- it was rejected because it adds an extra byte code to all
> code using those operators (the majority of which don't need it).

The semantic objection that I raised -- short circuiting means that you
can't correctly overload 'True and numpy_array', because unlike all other
binops the overload must be defined on the left hand argument -- does apply
to PEP 335 AFAICT. This problem is IMHO serious enough that even if PEP 335
were accepted today I'm not entirely sure that numpy would actually
implement the overloads due to the headaches it would cause for teaching
and code review -- we'd have to have some debate about it at least.

(Possibly useful analogy: Having to always double check that the array
argument appears on the left rather than the right is kinda like how the
old 'a and b or c' idiom forces you to constantly keep an extra special
rule in the back of your head and always double check that b cannot be
falsey whenever you read or write it, which IIUC was one of the major
reasons why it was considered an insufficient substitute for a real ternary
operator.)

-n
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151124/e7188569/attachment.html>


More information about the Python-ideas mailing list