https://github.com/python/cpython/commit/894af95edf7d5a1b0ebdc3699889743c8f41baf1
commit: 894af95edf7d5a1b0ebdc3699889743c8f41baf1
branch: main
author: Jeff Epler <[email protected]>
committer: picnixz <[email protected]>
date: 2026-09-09T11:22:18+02:00
summary:
gh-155966: Correct handling of `math.tanpi` poles (#155980)
``math.tanpi`` now raises a ``ValueError`` for half-integer values
(e.g., ``tanpi(0.5)``), as these are poles of the function.
files:
A Misc/NEWS.d/next/Library/2026-08-17-17-39-41.gh-issue-155966.0YOADY.rst
M Lib/test/mathdata/math_testcases.txt
M Lib/test/test_math.py
M Modules/mathmodule.c
diff --git a/Lib/test/mathdata/math_testcases.txt
b/Lib/test/mathdata/math_testcases.txt
index 4a38a3666bab208..b7a099ce92a3133 100644
--- a/Lib/test/mathdata/math_testcases.txt
+++ b/Lib/test/mathdata/math_testcases.txt
@@ -1311,9 +1311,9 @@ atan2pi20000 atan2pi inf 0 -> 0.5
atan2pi20001 atan2pi -inf 0 -> -0.5
atan2pi20002 atan2pi nan 0 -> nan
-atan2pi20000 atan2pi inf -0 -> 0.5
-atan2pi20001 atan2pi -inf -0 -> -0.5
-atan2pi20002 atan2pi nan -0 -> nan
+atan2pi21000 atan2pi inf -0 -> 0.5
+atan2pi21001 atan2pi -inf -0 -> -0.5
+atan2pi21002 atan2pi nan -0 -> nan
atan2pi20003 atan2pi inf 1 -> 0.5
atan2pi20004 atan2pi -inf 1 -> -0.5
@@ -1339,9 +1339,9 @@ atan2pi30000 atan2pi 0 inf -> 0.0
atan2pi30001 atan2pi 0 -inf -> 1.0
atan2pi30002 atan2pi 0 nan -> nan
-atan2pi30000 atan2pi -0 inf -> -0.0
-atan2pi30001 atan2pi -0 -inf -> -1.0
-atan2pi30002 atan2pi -0 nan -> nan
+atan2pi31000 atan2pi -0 inf -> -0.0
+atan2pi31001 atan2pi -0 -inf -> -1.0
+atan2pi31002 atan2pi -0 nan -> nan
atan2pi30003 atan2pi 1 inf -> 0.0
atan2pi30004 atan2pi 1 -inf -> 1.0
@@ -2247,3 +2247,8 @@ tanpi10275 tanpi -1.6591963470121216 -> 1.829921944286168
tanpi20001 tanpi inf -> nan invalid
tanpi20002 tanpi -inf -> nan invalid
tanpi20003 tanpi nan -> nan
+
+tanpi30001 tanpi 0.5 -> inf divide-by-zero
+tanpi30002 tanpi -0.5 -> -inf divide-by-zero
+tanpi30003 tanpi 1.5 -> -inf divide-by-zero
+tanpi30004 tanpi -1.5 -> inf divide-by-zero
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py
index a27996dd01c9d12..a1250c668223e7f 100644
--- a/Lib/test/test_math.py
+++ b/Lib/test/test_math.py
@@ -2144,7 +2144,12 @@ def test_mtestfile(self):
fail_fmt = "{}: {}{!r}: {}"
failures = []
+ ids = set()
for id, fn, args, expected, flags in parse_mtestfile(math_testcases):
+ if id in ids:
+ failures.append(f"Duplicate test id {id}")
+ ids.add(id)
+
func = getattr(math, fn)
if 'invalid' in flags or 'divide-by-zero' in flags:
diff --git
a/Misc/NEWS.d/next/Library/2026-08-17-17-39-41.gh-issue-155966.0YOADY.rst
b/Misc/NEWS.d/next/Library/2026-08-17-17-39-41.gh-issue-155966.0YOADY.rst
new file mode 100644
index 000000000000000..2f556aef54a63a0
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-08-17-17-39-41.gh-issue-155966.0YOADY.rst
@@ -0,0 +1,2 @@
+:func:`math.tanpi` now raises :exc:`ValueError` for half-integer values
+(e.g., ``tanpi(1.5)``), as these are poles of the function.
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 7988a77ab0abcca..16e7231214af2df 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -1343,10 +1343,10 @@ FUNC1D(tan, tan, 0,
FUNC1(tanh, tanh, 0,
"tanh($module, x, /)\n--\n\n"
"Return the hyperbolic tangent of x.")
-FUNC1D(tanpi, m_tanpi, 1,
+FUNC1D(tanpi, m_tanpi, 0,
"tanpi($module, x, /)\n--\n\n"
"Return the tangent of x (measured in half-turns).",
- "expected a finite input, got %s")
+ "expected a finite input not equal to a half-integer, got %s")
/* Precision summation function as msum() by Raymond Hettinger in
<https://code.activestate.com/recipes/393090-binary-floating-point-summation-accurate-to-full-p/>,
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]