[Python-ideas] Changing the meaning of bool.__invert__
Random832
random832 at fastmail.com
Thu Apr 7 12:23:42 EDT 2016
On Thu, Apr 7, 2016, at 12:00, Joseph Martinot-Lagarde wrote:
> Ethan Furman <ethan at ...> writes:
>
> > > --> ~False
> > > -1
> > > --> ~True
> > > -2
> > >
> > No. bool is a subclass of int, and changing that now would be a serious
> > breach of backward-compatibility, not to mention breaking existing code
> > for no good reason.
>
> I get that "technically" it would be a backward incompatible change, but
> any
> code that relies on `~True == -2` has other problems than backward
> compatibility.
It's more a combination of other things that code may rely on:
True == 1
False == 0
False + 1, False + True # truthy
True + True == 2 # imagine implementing count_if_true() as sum(map(bool,
...))
More information about the Python-ideas
mailing list