Python 3.1 inline division override

pythonpython-3.x

I don't know if this is a bug in 3.1, but if I remember correctly "inline" division worked like this in pre-3k versions:

Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
...     def __init__(self, x):
...             self.x = x
...     def __idiv__(self, y):
...             self.x /= y
...
>>> a = A(5)
>>> a /= 2

However, 3.1 gives me this:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for /=: 'A' and 'int'

… or am I missing something?

Best Solution

Gaaah! Found __floordiv__ and __truediv__. Sorry!

If you'd like to tell me why 2to3 doesn't translate __idiv__ into a __truediv__ with a __floordiv__(self, y): self.__truediv__(y), please go ahead!