diff -r a6af8ea3488b jython/Lib/test/test_float_jy.py --- a/jython/Lib/test/test_float_jy.py Sun May 18 23:36:01 2008 -0400 +++ b/jython/Lib/test/test_float_jy.py Sat May 24 00:42:01 2008 -0400 @@ -59,6 +59,9 @@ class FloatTestCase(unittest.TestCase): self.assertEqual('%.2g' % 99, '99') self.assertEqual('%.2g' % 100, '1e+02') + def test_float_none(self): + self.assertRaises(TypeError, float, None) + def test_main(): test_support.run_unittest(FloatTestCase) diff -r a6af8ea3488b jython/src/org/python/core/PyFloat.java --- a/jython/src/org/python/core/PyFloat.java Sun May 18 23:36:01 2008 -0400 +++ b/jython/src/org/python/core/PyFloat.java Sat May 24 00:42:01 2008 -0400 @@ -23,16 +23,33 @@ public class PyFloat extends PyObject PyObject[] args, String[] keywords) { ArgParser ap = new ArgParser("float", args, keywords, new String[] { "x" }, 0); PyObject x = ap.getPyObject(0, null); - if (new_.for_type == subtype) { - if (x == null) { + if (x == null) { + if (new_.for_type == subtype) { return new PyFloat(0.0); - } - return x.__float__(); - } else { - if (x == null) { + } else { return new PyFloatDerived(subtype, 0.0); } - return new PyFloatDerived(subtype, x.__float__().getValue()); + } else { + PyFloat floatObject = null; + try { + floatObject = x.__float__(); + } catch (PyException e) { + if (Py.matchException(e, Py.AttributeError)) { + // Translate AttributeError to TypeError + // XXX: We are using the same message as CPython, even if + // it is not strictly correct (instances of types + // that implement the __float__ method are also + // valid arguments) + throw Py.TypeError( + "float() argument must be a string or a number"); + } + throw e; + } + if (new_.for_type == subtype) { + return floatObject; + } else { + return new PyFloatDerived(subtype, floatObject.getValue()); + } } }