GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||
GeezerVison is showing github.com — #2240 Recursion error when doing reversed python operations on C# types by gertdreyer · Pull Request #2327 · pythonnet/pythonnet Conversation
Contributor
What does this fix? Explain your changes.Reverse operators were not implemented correctly for C# types which resulted in Recursion errors when embedding C# in Python. Changed the model binding process to add reverse operators for all applicable types. Added a flag to MethodBinder that signals the operation is a reversed operation and that the arguments to the operator needs to be reversed. Added tests and an wrapper object for int without overloaded operator methods and a wrapper codec to test the reverse operations (and forward operator on the same type for safety). Does this close any currently open issues?This should resolve #2240. Any other comments?... ChecklistCheck all those that are applicable and complete.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
gertdreyer
force-pushed
the
bugfix/recursionError
branch
from
1ae96dd to
c256746
Compare
lostmsu
reviewed
|
|
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.
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
d4e1fe9 to
4ea33fe
Compare
4ea33fe to
5277ed9
Compare
There was an error while loading. Please reload this page.
| /// <param name="argsReversed">Reverse arguments of methods. Used for methods such as __radd__, __rsub__, __rmod__ etc</param> | ||
| /// <returns>A Binding if successful. Otherwise null.</returns> | ||
| internal Binding? Bind(BorrowedReference inst, BorrowedReference args, BorrowedReference kw) | ||
| internal Binding? Bind(BorrowedReference inst, BorrowedReference args, BorrowedReference kw, bool argsReversed = false) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Do you need to pass this parameter at all? Don't you have the field?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Cleaned it up a bit. I missed that... The one method is static though so we will need to still pass it there...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
3409d88 to
38fa8f2
Compare
38fa8f2 to
ed2505c
Compare
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
RecursionError when substracting System Decimal from Python Decimal
There was an error while loading. Please reload this page.