#2240 Recursion error when doing reversed python operations on C# types by gertdreyer · Pull Request #2327 · pythonnet/pythonnet

Changes made...

I traced it down to the nb_add, nb_mul, etc slots only having the forward operators defined/linked for C# types being used in Python, this somehow caused the RecursionError when any reverse operators are called as they are probably just pointing to random pointers.

py * cs calls py.__mul__(cs) which is returns not implemented for the cs type and codecs does not get called prior to the mul call which results in cs.__rmul__(py) being called which caused the recursion error. I do not believe that there are problems with the codec system but it is needed to test this due to being on both sides of the CLR boundary.

It seems there were only catered for forward operators when both are the different (with overloaded operators, i.e. OwnInt - Int64 and Int64 - OwnInt). Thus all the code to detect whether a call is a reverse operator tested based on calling and passed types. Thus when called with the same types it could never detect it was a reversed operation even if it were defined. This needed some changes to the MethodBinding and ModelBinding to ensure the reversed calls are linked to the right C# operators and called with the arguments swapped.