For those interested in the future of the division operator a la PEP 238, I've produced a reasonably complete patch (relative to the CVS trunk, but it probably also works for the descr-branch or the 2.2a1 release).
Get it here:
It works as follows:
- unconditionally, there's a new operator // that will always do int division (and an in-place companion //=).
- by default, / is unchanged (and so is /=).
- after "from __future__ import division", / is changed to return a float result from int or long operands (and so is /=).
Read the patch description for more details; the implementation of int and float division are semi-lame.
There's no warning yet for int division returning a truncated result; I'm not sure if I want such a warning to be part of 2.2 (maybe if it's off by default).
I'm cc'ing Bruce Sherwood and Davin Scherer, because they asked for this and used a similar implementation in VPython. When this patch (or something not entirely unlike it) is accepted into Python 2.2, they will no longer have to maintain their own hacked Python. (We've already added 10**-15 returning a float to 2.2a1, also specifically for them; that was easier because it used to be an error, so no backwards compatibility code or future statement is necessary there.)
I thought again about the merits of the '//' operator vs. 'div' (either as a function or as a keyword binary operator), and figured that '//' is the best choice: it doesn't introduce a new keyword (which would cause more pain), and it works as an augmented assignment (//=) as well.
--Guido van Rossum (home page: http://www.python.org/%7Eguido/)