From 1b70f8327b08b45dee8f46636042d10a4201f6a1 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sat, 28 Oct 2023 07:52:04 +0300 Subject: [PATCH] gh-111342: fix typo in math.sumprod (GH-111416) --- Lib/test/test_math.py | 1 + .../next/Library/2023-10-28-04-21-17.gh-issue-111342.m8Ln1k.rst | 1 + Modules/mathmodule.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2023-10-28-04-21-17.gh-issue-111342.m8Ln1k.rst diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index d5d2197c36b254..bab732cdea5888 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -1325,6 +1325,7 @@ def test_sumprod_accuracy(self): sumprod = math.sumprod self.assertEqual(sumprod([0.1] * 10, [1]*10), 1.0) self.assertEqual(sumprod([0.1] * 20, [True, False] * 10), 1.0) + self.assertEqual(sumprod([True, False] * 10, [0.1] * 20), 1.0) self.assertEqual(sumprod([1.0, 10E100, 1.0, -10E100], [1.0]*4), 2.0) @support.requires_resource('cpu') diff --git a/Misc/NEWS.d/next/Library/2023-10-28-04-21-17.gh-issue-111342.m8Ln1k.rst b/Misc/NEWS.d/next/Library/2023-10-28-04-21-17.gh-issue-111342.m8Ln1k.rst new file mode 100644 index 00000000000000..57707fd4acf1b2 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-10-28-04-21-17.gh-issue-111342.m8Ln1k.rst @@ -0,0 +1 @@ +Fixed typo in :func:`math.sumprod`. diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index a4d94665592351..6cd61e9ab75424 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -2832,7 +2832,7 @@ math_sumprod_impl(PyObject *module, PyObject *p, PyObject *q) PyErr_Clear(); goto finalize_flt_path; } - } else if (q_type_float && (PyLong_CheckExact(p_i) || PyBool_Check(q_i))) { + } else if (q_type_float && (PyLong_CheckExact(p_i) || PyBool_Check(p_i))) { flt_q = PyFloat_AS_DOUBLE(q_i); flt_p = PyLong_AsDouble(p_i); if (flt_p == -1.0 && PyErr_Occurred()) {