mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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:
parent
65fc98e7b1
commit
e9ba3705de
3 changed files with 16 additions and 3 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue