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

Joseph Martinot-Lagarde contrebasse at gmail.com
Thu Apr 7 12:02:37 EDT 2016


Steven D'Aprano <steve at ...> writes:

> It also breaks a fundamental property of most mathematical relations:
> 
> if a == b, then f(a) == f(b) 
> 
> (assuming f(a) and f(b) are defined for the type of both a and b).
> 
> That is currently true for bools:
> 
> py> (True == 1) and (~True == ~1)
> True
> py> (False==0) and (~False == ~0)
> True
> 
> You want ~b to return `not b`:
> 
> py> (True == 1) and (False == ~1)
> False
> py> (False==0) and (True == ~0)
> False

How about the str function ?
str(True) != str(1)
str(False) != str(0)

True == 1 is not a mathematical relation, it is python's history.



More information about the Python-ideas mailing list