Index: src/org/python/core/PyObject.java =================================================================== --- src/org/python/core/PyObject.java (revision 6102) +++ src/org/python/core/PyObject.java (working copy) @@ -264,6 +264,19 @@ if (c.isInstance(getJavaProxy())) { return javaProxy; } + + // attempt __float__ (maybe __int__ too?) + if (c == Double.class || c == Float.class) { + try { + System.err.println("py2float:" + this); + return __float__().getValue(); // autobox + } catch (PyException pye) { + if (!Py.matchException(pye, Py.AttributeError)) { + throw pye; + } + } + } + return Py.NoConversion; } Index: Lib/test/test_float_jy.py =================================================================== --- Lib/test/test_float_jy.py (revision 6102) +++ Lib/test/test_float_jy.py (working copy) @@ -98,9 +98,21 @@ # regression in 2.5 alphas self.assertEqual(4.0 ** Foo(), 16.0) +class FauxFloatTestCase(unittest.TestCase): + + # XXX - maybe use inverse to verify... need to read up on math functions + def test_faux(self): + class F(object): + def __float__(self): + return 1.6 + import math + math.cos(F()) + + + def test_main(): - test_support.run_unittest(FloatTestCase) + test_support.run_unittest(FloatTestCase, FauxFloatTestCase) if __name__ == '__main__': test_main()