diff options
author | Zackery Spytz <zspytz@gmail.com> | 2020-03-14 10:45:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-14 10:45:32 (GMT) |
commit | 5208b4b37953a406db0ed6a9db545c2948dde989 (patch) | |
tree | 249b714d2e6476f7aced7368ad4bb18c929a13f3 /Lib | |
parent | 3a8c56295d6272ad2177d2de8af4c3f824f3ef92 (diff) | |
download | cpython-5208b4b37953a406db0ed6a9db545c2948dde989.zip cpython-5208b4b37953a406db0ed6a9db545c2948dde989.tar.gz cpython-5208b4b37953a406db0ed6a9db545c2948dde989.tar.bz2 |
bpo-39871: Fix possible SystemError in atan2, copysign and remainder (GH-18806)
In math_2(), the first PyFloat_AsDouble() call should be checked
for failure before the second call.
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_math.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index cc39402..4b848a5 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -1992,6 +1992,22 @@ class MathTests(unittest.TestCase): with self.subTest(x=x): self.assertEqual(math.ulp(-x), math.ulp(x)) + def test_issue39871(self): + # A SystemError should not be raised if the first arg to atan2(), + # copysign(), or remainder() cannot be converted to a float. + class F: + def __float__(self): + self.converted = True + 1/0 + for func in math.atan2, math.copysign, math.remainder: + y = F() + with self.assertRaises(TypeError): + func("not a number", y) + + # There should not have been any attempt to convert the second + # argument to a float. + self.assertFalse(getattr(y, "converted", False)) + # Custom assertions. def assertIsNaN(self, value): |