From f2e014282e929866dca9aad926aad23f80888f56 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Thu, 17 Apr 2025 08:26:14 +0300 Subject: [PATCH 1/2] gh-101410: revert loghelper() change in 75f59bb for integer input --- Lib/test/test_math.py | 2 +- Modules/mathmodule.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index bfc55e7bbaba0a..dd92cead217aa3 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -2536,7 +2536,7 @@ def test_exception_messages(self): math.log(x) x = -123 with self.assertRaisesRegex(ValueError, - f"expected a positive input, got {x}"): + f"expected a positive input"): math.log(x) with self.assertRaisesRegex(ValueError, f"expected a float or nonnegative integer, got {x}"): diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 20d3c3192ba2e4..bc259c91d9476e 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -2213,8 +2213,10 @@ loghelper(PyObject* arg, double (*func)(double)) /* Negative or zero inputs give a ValueError. */ if (!_PyLong_IsPositive((PyLongObject *)arg)) { - PyErr_Format(PyExc_ValueError, - "expected a positive input, got %S", arg); + /* The input can be an arbitrary large integer, so we + don't include it's value in the error message. */ + PyErr_SetString(PyExc_ValueError, + "expected a positive input"); return NULL; } From 9a8d5f5ef25488b62a7ab45939956a02cf7858c6 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Thu, 17 Apr 2025 10:27:35 +0300 Subject: [PATCH 2/2] Update Lib/test/test_math.py Co-authored-by: Serhiy Storchaka --- Lib/test/test_math.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index dd92cead217aa3..6ff7c40d81356b 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -2536,7 +2536,7 @@ def test_exception_messages(self): math.log(x) x = -123 with self.assertRaisesRegex(ValueError, - f"expected a positive input"): + "expected a positive input$"): math.log(x) with self.assertRaisesRegex(ValueError, f"expected a float or nonnegative integer, got {x}"):