Это связано с разным поведением оператора деления между Python 2 и 3.
PS C:\Users\TigerhawkT3> py -2
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
... def __div__(self, other):
... return 'call div'
... def __truediv__(self, other):
... return 'call truediv'
... def __floordiv__(self, other):
... return 'call floordiv'
...
>>> a = A()
>>> a/3
'call div'
>>> a//3
'call floordiv'
>>> exit()
PS C:\Users\TigerhawkT3> py
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
... def __div__(self, other):
... return 'call div'
... def __truediv__(self, other):
... return 'call truediv'
... def __floordiv__(self, other):
... return 'call floordiv'
...
>>> a = A()
>>> a/3
'call truediv'
>>> a//3
'call floordiv'
Вам потребуется определить специальный метод __truediv__
, а не __div__
, для Python3. Подробнее см. Модели данных для Python 2 и Python 3 .