The __invert__ methods, which controls the behaviour of the ~ operator, of Integers and ints are different.
In Python, for an int x, its invert ~x is defined to be its
two's complement and is given by -1-x.
Unfortunately this difference means that ~x different results in Sage and Python and so is causing some of my scripts and packages that run under Python to break under Sage. Most notably, that under Sage ~0 raises a "ZeroDivisionError: Rational division by zero" error rather than returning -1.
Looking through the git history it appears that this has been the convention since at least
October 2006. Is there a reason why __invert__ was chosen to act this way rather than match the Python convention?