]> granicus.if.org Git - python/commitdiff
Improve exception message raised by PyFloat_AsDouble if the object does not
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>
Mon, 18 Nov 2002 16:06:21 +0000 (16:06 +0000)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>
Mon, 18 Nov 2002 16:06:21 +0000 (16:06 +0000)
have a nb_float slot.  This matches what PyInt_AsLong does.

Objects/floatobject.c

index 36e861e0a9e52b9dc8f4f0b612200388e84cb43b..924b31293b0f259720899cf49331fa6b16ca8625 100644 (file)
@@ -202,12 +202,16 @@ PyFloat_AsDouble(PyObject *op)
        if (op && PyFloat_Check(op))
                return PyFloat_AS_DOUBLE((PyFloatObject*) op);
 
-       if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
-           nb->nb_float == NULL) {
+       if (op == NULL) {
                PyErr_BadArgument();
                return -1;
        }
 
+       if ((nb = op->ob_type->tp_as_number) == NULL || nb->nb_float == NULL) {
+               PyErr_SetString(PyExc_TypeError, "a float is required");
+               return -1;
+       }
+
        fo = (PyFloatObject*) (*nb->nb_float) (op);
        if (fo == NULL)
                return -1;