diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-05-26 15:43:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-26 15:43:38 (GMT) |
commit | 578c3955e0222ec7b3146197467fbb0fcfae12fe (patch) | |
tree | 1314ca1eb6153feaf3fb1cae341784270ce24c32 /Modules/mathmodule.c | |
parent | 8ad052464a4e0aef9a11663b80f187087b773592 (diff) | |
download | cpython-578c3955e0222ec7b3146197467fbb0fcfae12fe.zip cpython-578c3955e0222ec7b3146197467fbb0fcfae12fe.tar.gz cpython-578c3955e0222ec7b3146197467fbb0fcfae12fe.tar.bz2 |
bpo-37999: No longer use __int__ in implicit integer conversions. (GH-15636)
Only __index__ should be used to make integer conversions lossless.
Diffstat (limited to 'Modules/mathmodule.c')
-rw-r--r-- | Modules/mathmodule.c | 32 |
1 files changed, 2 insertions, 30 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index f1d59c0..5b96631 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -2047,37 +2047,9 @@ math_factorial(PyObject *module, PyObject *arg) { long x, two_valuation; int overflow; - PyObject *result, *odd_part, *pyint_form; - - if (PyFloat_Check(arg)) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Using factorial() with floats is deprecated", - 1) < 0) - { - return NULL; - } - PyObject *lx; - double dx = PyFloat_AS_DOUBLE((PyFloatObject *)arg); - if (!(Py_IS_FINITE(dx) && dx == floor(dx))) { - PyErr_SetString(PyExc_ValueError, - "factorial() only accepts integral values"); - return NULL; - } - lx = PyLong_FromDouble(dx); - if (lx == NULL) - return NULL; - x = PyLong_AsLongAndOverflow(lx, &overflow); - Py_DECREF(lx); - } - else { - pyint_form = PyNumber_Index(arg); - if (pyint_form == NULL) { - return NULL; - } - x = PyLong_AsLongAndOverflow(pyint_form, &overflow); - Py_DECREF(pyint_form); - } + PyObject *result, *odd_part; + x = PyLong_AsLongAndOverflow(arg, &overflow); if (x == -1 && PyErr_Occurred()) { return NULL; } |