From: <pj...@us...> - 2009-03-27 19:03:55
|
Revision: 6109 http://jython.svn.sourceforge.net/jython/?rev=6109&view=rev Author: pjenvey Date: 2009-03-27 19:03:30 +0000 (Fri, 27 Mar 2009) Log Message: ----------- have java integration translate faux-floats (objects implementing __float__) to Java floats patch from zyasoft fixes #1198 Modified Paths: -------------- trunk/jython/Lib/test/test_float_jy.py trunk/jython/src/org/python/core/PyObject.java Modified: trunk/jython/Lib/test/test_float_jy.py =================================================================== --- trunk/jython/Lib/test/test_float_jy.py 2009-03-26 16:49:14 UTC (rev 6108) +++ trunk/jython/Lib/test/test_float_jy.py 2009-03-27 19:03:30 UTC (rev 6109) @@ -98,7 +98,13 @@ # regression in 2.5 alphas self.assertEqual(4.0 ** Foo(), 16.0) + def test_faux(self): + class F(object): + def __float__(self): + return 1.6 + self.assertEqual(math.cos(1.6), math.cos(F())) + def test_main(): test_support.run_unittest(FloatTestCase) Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2009-03-26 16:49:14 UTC (rev 6108) +++ trunk/jython/src/org/python/core/PyObject.java 2009-03-27 19:03:30 UTC (rev 6109) @@ -264,6 +264,20 @@ if (c.isInstance(getJavaProxy())) { return javaProxy; } + + // convert faux floats + // XXX: should also convert faux ints, but that breaks test_java_visibility + // (ReflectedArgs resolution) + if (c == Double.TYPE || c == Double.class || c == Float.TYPE || c == Float.class) { + try { + return __float__().getValue(); + } catch (PyException pye) { + if (!Py.matchException(pye, Py.AttributeError)) { + throw pye; + } + } + } + return Py.NoConversion; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |