From: <bc...@wo...> - 2000-10-29 19:33:06
|
Hi, Daniel Wood discovered that a python float does not autocoerce to a java int when passed to a java method. Jython 2.0 pre-alpha on java1.3.0 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import java >>> java.lang.Integer(1.0) Traceback (innermost last): File "<console>", line 1, in ? TypeError: java.lang.Integer(): 1st arg can't be coerced to int or String >>> The documentation in usejava.html says that floats will be converted to ints, so there is a bug in either the docs or in the code. But which is it? Fixing the code could look like this: Index: PyFloat.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyFloat.java,v retrieving revision 2.2 diff -u -r2.2 PyFloat.java --- PyFloat.java 1999/10/04 22:21:46 2.2 +++ PyFloat.java 2000/10/29 19:26:28 @@ -68,6 +68,9 @@ if (c == Float.TYPE || c == Float.class) { return new Float(value); } + if (c == Integer.TYPE || c == Integer.class) { + return new Integer((int) value); + } return super.__tojava__(c); } But this cause silent loss of information, so I would prefer that we fix the documentation. Does anyone have a strong opinion about this? regards, finn |