mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Improve exception message raised by PyFloat_AsDouble if the object does not
have a nb_float slot. This matches what PyInt_AsLong does.
This commit is contained in:
parent
26db587485
commit
2c77e90804
1 changed files with 6 additions and 2 deletions
|
@ -202,12 +202,16 @@ PyFloat_AsDouble(PyObject *op)
|
||||||
if (op && PyFloat_Check(op))
|
if (op && PyFloat_Check(op))
|
||||||
return PyFloat_AS_DOUBLE((PyFloatObject*) op);
|
return PyFloat_AS_DOUBLE((PyFloatObject*) op);
|
||||||
|
|
||||||
if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
|
if (op == NULL) {
|
||||||
nb->nb_float == NULL) {
|
|
||||||
PyErr_BadArgument();
|
PyErr_BadArgument();
|
||||||
return -1;
|
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);
|
fo = (PyFloatObject*) (*nb->nb_float) (op);
|
||||||
if (fo == NULL)
|
if (fo == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue