|
From: George Y. <gy...@cn...> - 2003-11-07 23:29:36
|
Hello, I'm implementing an auditing system with a framework written in Java and = a customization level written in Jython. The customization level often = pulls numeric values from the framework and may manipulate or compare = those values and put them back. The values are of various numeric types = (Integer, Long, BigInteger, BigDecimal) and may be compared against = Python literals. I have the following scenario: 1) A java.lang.Long is retrieved as a Python long 2) the Python long is set back into the framework (which makes it a = java.math.BigInteger) 3) the java.math.BigInteger is retrieved as a wrapped instance 4) I try to compare the wrapped instance against a Python literal (which = returns an arbitrary result) The progression of the types is transparent up until the comparison, and = other math like addition and subtraction would still work since = PyLong.__add__ attempts coercion. Here's a simpler example that = demonstrates the case: >>> from java.util import * >>> jythonLong =3D 3L >>> print jythonLong > 0 1 >>> v =3D Vector() >>> v.add(jythonLong) 1 >>> javaLong =3D v.get(0) >>> print javaLong > 0 0 >>> print javaLong.__class__ java.math.BigInteger >>> print jythonLong.__class__ org.python.core.PyLong >>> =20 I was wondering if it made sense to have PyLong and PyInteger attempt = coercion for comparisons? If not, or in the interim, does anyone have a = suggestion on how to deal with this issue? =20 |