While the switch to Python 3 did an excellent job in removing some of
the old inconsistencies we had in the language, pretty much everyone
agrees that some other backwards-incompatible changes could be made to
remove some old warts and bring even more consistency to Python.
Since Python 4 is getting closer and closer, I think it’s time to
finally discuss some of the most obvious changes we should do for
Python 4. Here is the list I compiled:
- The / operator returns floats, which loses information when both of
the operands are integer. In Python 4, “1 / 2” should return a
decimal.Decimal. To ease the transition, we propose to add a new “from
__future__ import decimal_division” in Python 3.9 to enable this
behavior.
More broadly, one of the best changes in Python 3 was the sanitization of the string/unicode logic: in Python 2 str and unicode were mostly-but-not-always interchangeable, but not always, and that led to a lot of hard to debug errors. Python 3 fixed this by separating the two more cleanly. Python 4 has the opportunity to do something similar to separate out another pair of easily confused types: int and float.
Broadly speaking, we should use float for human-understandable numbers, and int for things that map directly to memory offsets in the computer, and we should avoid mixing them. This suggests the following changes:
- int + float (and generally any mixed operation between ints and floats) should throw a TypeError
- len() should return a float
- list.__getitem__ should only accepts ints, not floats
- integer overflow should use two's complement wraparound instead of infinite precision