I'm trying to use the answer from this question and came across some interesting behaviour:
from sympy import Symbol
class MySymbol(Symbol):
def __new__(cls, symbol, description):
obj = super().__new__(cls, symbol)
obj.description = description
return obj
symbolx = MySymbol('x', 100)
symbolx2 = MySymbol('x', 200)
symboly = MySymbol('y', 300)
print(symbolx.description)
print(symbolx2.description)
print(symboly.description)
returns:
200
200
300
Instead of the expected
100
200
300
My best guess is that sympy
returns the same Symbol
for a given name. Is there any way to work around this?