bpo-33083 - Make math.factorial reject arguments that are not int-like (GH-6149)

math.factorial() was accepting non-integral Decimal instances. This is inconsistent with the actual behaviour for floats, which are not accepted.
This commit is contained in:
Pablo Galindo 2018-09-03 22:20:06 +01:00 committed by GitHub
parent 65fc98e7b1
commit e9ba3705de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View file

@ -1656,7 +1656,7 @@ math_factorial(PyObject *module, PyObject *arg)
{
long x;
int overflow;
PyObject *result, *odd_part, *two_valuation;
PyObject *result, *odd_part, *two_valuation, *pyint_form;
if (PyFloat_Check(arg)) {
PyObject *lx;
@ -1672,8 +1672,14 @@ math_factorial(PyObject *module, PyObject *arg)
x = PyLong_AsLongAndOverflow(lx, &overflow);
Py_DECREF(lx);
}
else
x = PyLong_AsLongAndOverflow(arg, &overflow);
else {
pyint_form = PyNumber_Index(arg);
if (pyint_form == NULL) {
return NULL;
}
x = PyLong_AsLongAndOverflow(pyint_form, &overflow);
Py_DECREF(pyint_form);
}
if (x == -1 && PyErr_Occurred()) {
return NULL;