I made a custom C-module to Python 2 a few years ago, which I now upgrade to Python 3. The PyNumberMethods
definition changed between 2 and 3, to register a class supporting certain operators.
Python 2
The class had two division operators. I used the first one and it worked.
typedef struct {
binaryfunc nb_add;
binaryfunc nb_subtract;
binaryfunc nb_multiply;
binaryfunc nb_divide; <-------
binaryfunc nb_remainder;
[...]
binaryfunc nb_true_divide; <-------
[...]
} PyNumberMethods;
Python 3
nb_divide
got removed, and instead there is nb_remainder
. Is this supposed to be the new function?
typedef struct {
binaryfunc nb_add;
binaryfunc nb_subtract;
binaryfunc nb_multiply;
binaryfunc nb_remainder; <-------
[...]
binaryfunc nb_true_divide; <-------
[...]
} PyNumberMethods;
I tried nb_true_divide
instead, and it also works. What is the difference between all these functions, and which one should I use if I want to support foo.vector() / 100.0