[Python-ideas] 1 + True = 2

Nick Coghlan ncoghlan at gmail.com
Sun Jun 5 15:04:34 EDT 2016


On 5 Jun 2016 11:38, "Giampaolo Rodola'" <g.rodola at gmail.com> wrote:
>
> On the other hand (and I'm gonna contradict myself with what I've just
said above) on chapter 4:
>
>        There's a small but vocal minority that would prefer to see
>        "textbook" bools that don't support arithmetic operations at
>        all, but most reviewers agree with me that bools should always
>        allow arithmetic operations.
>
> ...so maybe supporting arithmetical operations was also a primary
intention, in which case my question is "why?".

The inheritance from int meant the default behaviour was to support
type-promoting integer arithmetic operations in addition to bitwise
arithmetic.

That changes the question from "Why support that?" to "Why do the extra
design, documentation and implementation work needed to prevent that?".

The fact that "1 + True == 2" is surprising hasn't proven to be enough to
motivate anyone to define the precise subset of operations they want to
prevent, and then make the case for those restrictions as Python's native
behaviour.

Cheers,
Nick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160605/38c90bbc/attachment-0001.html>


More information about the Python-ideas mailing list