Make the error msgs in our pow() implementations consistent.

This commit is contained in:
Tim Peters 2001-09-05 06:24:58 +00:00
parent d893fd68bd
commit 4c483c4d8e
3 changed files with 15 additions and 8 deletions

View file

@ -495,8 +495,8 @@ float_pow(PyObject *v, PyObject *w, PyObject *z)
double iv, iw, ix; double iv, iw, ix;
if ((PyObject *)z != Py_None) { if ((PyObject *)z != Py_None) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError, "pow() 3rd argument not "
"3rd argument to floating pow() must be None"); "allowed unless all other arguments are integers");
return NULL; return NULL;
} }

View file

@ -589,8 +589,8 @@ int_pow(PyIntObject *v, PyIntObject *w, PyIntObject *z)
CONVERT_TO_LONG(w, iw); CONVERT_TO_LONG(w, iw);
if (iw < 0) { if (iw < 0) {
if ((PyObject *)z != Py_None) { if ((PyObject *)z != Py_None) {
PyErr_SetString(PyExc_TypeError, "integer pow() arg " PyErr_SetString(PyExc_TypeError, "pow() 2nd argument "
"3 must not be specified when arg 2 is < 0"); "cannot be negative when 3rd argument specified");
return NULL; return NULL;
} }
/* Return a float. This works because we know that /* Return a float. This works because we know that
@ -603,7 +603,7 @@ int_pow(PyIntObject *v, PyIntObject *w, PyIntObject *z)
CONVERT_TO_LONG(z, iz); CONVERT_TO_LONG(z, iz);
if (iz == 0) { if (iz == 0) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"pow() arg 3 cannot be 0"); "pow() 3rd argument cannot be 0");
return NULL; return NULL;
} }
} }

View file

@ -1686,14 +1686,21 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
return Py_NotImplemented; return Py_NotImplemented;
} }
if (c != Py_None && ((PyLongObject *)c)->ob_size == 0) {
PyErr_SetString(PyExc_ValueError,
"pow() 3rd argument cannot be 0");
z = NULL;
goto error;
}
size_b = b->ob_size; size_b = b->ob_size;
if (size_b < 0) { if (size_b < 0) {
Py_DECREF(a); Py_DECREF(a);
Py_DECREF(b); Py_DECREF(b);
Py_DECREF(c); Py_DECREF(c);
if (x != Py_None) { if (x != Py_None) {
PyErr_SetString(PyExc_TypeError, "integer pow() arg " PyErr_SetString(PyExc_TypeError, "pow() 2nd argument "
"3 must not be specified when arg 2 is < 0"); "cannot be negative when 3rd argument specified");
return NULL; return NULL;
} }
/* Return a float. This works because we know that /* Return a float. This works because we know that