首页 > 解决方案 > 我可以防止我的自定义类被简化吗?

问题描述

我正在构建我的自定义类,它是object. (由于__r(operator)__优先级,没有其他超类可供选择。)

由于这个类不是sympy类,所以每当我尝试将它应用于 sympy 函数时,它都会被 sympified,这会造成麻烦。

当它被简化时,有没有办法让它自己返回?例如,就像sympify(sin(x))返回一样sin(x),我希望我的类的实例以这样的方式运行:sympify(instance)返回instance

标签: pythonsympy

解决方案


Try adding a def for _sympy_ in your class: def _sympy_(self): return self or maybe Basic(self)...but then SymPy won't be able to work with such expressions. Can you give an example of what you are trying to do? There is the CantSympify mixin available, too, but that will prevent the object from being sympified at all.


推荐阅读