Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Python custom justifications with Decimal scores
The translator automatically converts the result of Java method calls on Java objects into the corresponding Python types. This is normally wanted, since it allow users to use the result of ConstraintCollectors (which are Java objects). However, `to_python_score` does not want this; it expects the normal Java result. It is typically called in an untranslated context and thus usually does not run into this issue. However, when a custom justification function is used, it is called in a translation context. For normal scores, it works, since we don't access any properties of the long when creating the corresponding Python score. For decimal scores, we call toPlainString() so we can create a Python Decimal instance from a Java BigDecimal. Python Decimal does not have a toPlainString method normally, so it causes an attribute lookup failure at runtime. The fix is to add a toPlainString method to PythonDecimal, that just delegate to the toPlainString method of its value.
- Loading branch information