self.fail('Failures in test_mtestfile:\n ' +
'\n '.join(failures))
+ 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):
if (! PyArg_UnpackTuple(args, funcname, 2, 2, &ox, &oy))
return NULL;
x = PyFloat_AsDouble(ox);
+ if (x == -1.0 && PyErr_Occurred()) {
+ return NULL;
+ }
y = PyFloat_AsDouble(oy);
- if ((x == -1.0 || y == -1.0) && PyErr_Occurred())
+ if (y == -1.0 && PyErr_Occurred()) {
return NULL;
+ }
errno = 0;
PyFPE_START_PROTECT("in math_2", return 0);
r = (*func)(x, y);