You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RecursionError when substracting System Decimal from Python Decimal #2240
I'll have a look into the recursion (which I can reproduce and is a bug), but we don't actually by default provide conversions from/to Python decimals. You must be running a non-upstream version of Python.NET or have more code that you are not showing.
Pythonnet version: 3.0.3
Pythonnet version: 3.11
Dotnet 6.0: Windows and Linux
For a codec I am using a naive string based conversion of cs System.Decimal to py decimal.Decimal and the inverse, in our use case the possible loss of precision should not be a concern.
I have traced it down to the __rsub__ operation on the cs type.
Operation
Status
cs - py
Working
cs.__sub__(py)
Working
py - cs
RecursionError
py.__sub__(cs)
NotImplemented
cs.__rsub__(py)
RecursionError
The same happens with multiply and addition right-hand methods as well. As per the python rules for operators the forward operators are tried first and if they are NotImplemented for a type the right hand ones are tried where the RecursionError occurs. The codec conversion does not get called for the python decimal foward operators which results in the python decimal conversion code being called which throws the NotImplemented exception
Activity
dariooo512 commentedon Sep 19, 2023
I have the same issue:
same setup, here is my case:
maximum recursion depth exceeded while calling a Python object
File [...], line 4, in execute
total_discount += offer.Discount
hope it helps
filmor commentedon Sep 23, 2023
I'll have a look into the recursion (which I can reproduce and is a bug), but we don't actually by default provide conversions from/to Python decimals. You must be running a non-upstream version of Python.NET or have more code that you are not showing.
gertdreyer commentedon Feb 21, 2024
I have the same issue.
Pythonnet version: 3.0.3
Pythonnet version: 3.11
Dotnet 6.0: Windows and Linux
For a codec I am using a naive string based conversion of cs System.Decimal to py decimal.Decimal and the inverse, in our use case the possible loss of precision should not be a concern.
I have traced it down to the
__rsub__operation on the cs type.cs - pycs.__sub__(py)py - cspy.__sub__(cs)cs.__rsub__(py)The same happens with multiply and addition right-hand methods as well. As per the python rules for operators the forward operators are tried first and if they are NotImplemented for a type the right hand ones are tried where the RecursionError occurs. The codec conversion does not get called for the python decimal foward operators which results in the python decimal conversion code being called which throws the NotImplemented exception
Codec: