[Python-ideas] Changing the meaning of bool.__invert__

Antoine Pitrou solipsis at pitrou.net
Thu Apr 7 04:15:18 EDT 2016


On Thu, 7 Apr 2016 09:00:36 +0100
Mark Dickinson <dickinsm at gmail.com> wrote:
> On Thu, Apr 7, 2016 at 8:46 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> > Booleans currently have reasonable overrides for the bitwise binary
> > operators:
> >
> >>>> True | False
> > True
> >>>> True & False
> > False
> >>>> True ^ False
> > True
> 
> All those are consistent with bool being a subclass of int, in the
> sense that (for example) `int(True | False)` is identical to
> `int(True) | int(False)`.

However, the return type (bool in one place, int in another one) is
inconsistent, and the user-visible semantics are confusing...

Apparently someone went to the trouble of overriding __and__, __or__
and __xor__ for booleans, which is why it looks unexpected to leave
__invert__ alone.

Regards

Antoine.




More information about the Python-ideas mailing list