| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -860,6 +860,13 @@ logging.handlers | |||
| 860 | 860 | (Contributed by Charles Machalow in :gh:`132106`.) | |
| 861 | 861 | ||
| 862 | 862 | ||
| 863 | + math | ||
| 864 | + ---- | ||
| 865 | + | ||
| 866 | + * Added more detailed error messages for domain errors in the module. | ||
| 867 | + (Contributed by by Charlie Zhao and Sergey B Kirpichev in :gh:`101410`.) | ||
| 868 | + | ||
| 869 | + | ||
| 863 | 870 | mimetypes | |
| 864 | 871 | --------- | |
| 865 | 872 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -127,31 +127,31 @@ Trigonometric Functions | |||
| 127 | 127 | >>> sin(INF) | |
| 128 | 128 | Traceback (most recent call last): | |
| 129 | 129 | ... | |
| 130 | - ValueError: math domain error | ||
| 130 | + ValueError: expected a finite input, got inf | ||
| 131 | 131 | >>> sin(NINF) | |
| 132 | 132 | Traceback (most recent call last): | |
| 133 | 133 | ... | |
| 134 | - ValueError: math domain error | ||
| 134 | + ValueError: expected a finite input, got -inf | ||
| 135 | 135 | >>> sin(NAN) | |
| 136 | 136 | nan | |
| 137 | 137 | >>> cos(INF) | |
| 138 | 138 | Traceback (most recent call last): | |
| 139 | 139 | ... | |
| 140 | - ValueError: math domain error | ||
| 140 | + ValueError: expected a finite input, got inf | ||
| 141 | 141 | >>> cos(NINF) | |
| 142 | 142 | Traceback (most recent call last): | |
| 143 | 143 | ... | |
| 144 | - ValueError: math domain error | ||
| 144 | + ValueError: expected a finite input, got -inf | ||
| 145 | 145 | >>> cos(NAN) | |
| 146 | 146 | nan | |
| 147 | 147 | >>> tan(INF) | |
| 148 | 148 | Traceback (most recent call last): | |
| 149 | 149 | ... | |
| 150 | - ValueError: math domain error | ||
| 150 | + ValueError: expected a finite input, got inf | ||
| 151 | 151 | >>> tan(NINF) | |
| 152 | 152 | Traceback (most recent call last): | |
| 153 | 153 | ... | |
| 154 | - ValueError: math domain error | ||
| 154 | + ValueError: expected a finite input, got -inf | ||
| 155 | 155 | >>> tan(NAN) | |
| 156 | 156 | nan | |
| 157 | 157 | ||
@@ -169,11 +169,11 @@ True | |||
| 169 | 169 | >>> asin(INF), asin(NINF) | |
| 170 | 170 | Traceback (most recent call last): | |
| 171 | 171 | ... | |
| 172 | - ValueError: math domain error | ||
| 172 | + ValueError: expected a number in range from -1 up to 1, got inf | ||
| 173 | 173 | >>> acos(INF), acos(NINF) | |
| 174 | 174 | Traceback (most recent call last): | |
| 175 | 175 | ... | |
| 176 | - ValueError: math domain error | ||
| 176 | + ValueError: expected a number in range from -1 up to 1, got inf | ||
| 177 | 177 | >>> equal(atan(INF), PI/2), equal(atan(NINF), -PI/2) | |
| 178 | 178 | (True, True) | |
| 179 | 179 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2539,7 +2539,7 @@ def test_exception_messages(self): | |||
| 2539 | 2539 | "expected a positive input$"): | |
| 2540 | 2540 | math.log(x) | |
| 2541 | 2541 | with self.assertRaisesRegex(ValueError, | |
| 2542 | - f"expected a float or nonnegative integer, got {x}"): | ||
| 2542 | + f"expected a noninteger or positive integer, got {x}"): | ||
| 2543 | 2543 | math.gamma(x) | |
| 2544 | 2544 | x = 1.0 | |
| 2545 | 2545 | with self.assertRaisesRegex(ValueError, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Added more detailed messages for domain errors in the :mod:`math` module. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1076,17 +1076,20 @@ math_2(PyObject *const *args, Py_ssize_t nargs, | |||
| 1076 | 1076 | }\ | |
| 1077 | 1077 | PyDoc_STRVAR(math_##funcname##_doc, docstring); | |
| 1078 | 1078 | ||
| 1079 | - FUNC1(acos, acos, 0, | ||
| 1079 | + FUNC1D(acos, acos, 0, | ||
| 1080 | 1080 | "acos($module, x, /)\n--\n\n" | |
| 1081 | 1081 | "Return the arc cosine (measured in radians) of x.\n\n" | |
| 1082 | - "The result is between 0 and pi.") | ||
| 1083 | - FUNC1(acosh, acosh, 0, | ||
| 1082 | + "The result is between 0 and pi.", | ||
| 1083 | + "expected a number in range from -1 up to 1, got %s") | ||
| 1084 | + FUNC1D(acosh, acosh, 0, | ||
| 1084 | 1085 | "acosh($module, x, /)\n--\n\n" | |
| 1085 | - "Return the inverse hyperbolic cosine of x.") | ||
| 1086 | - FUNC1(asin, asin, 0, | ||
| 1086 | + "Return the inverse hyperbolic cosine of x.", | ||
| 1087 | + "expected argument value not less than 1, got %s") | ||
| 1088 | + FUNC1D(asin, asin, 0, | ||
| 1087 | 1089 | "asin($module, x, /)\n--\n\n" | |
| 1088 | 1090 | "Return the arc sine (measured in radians) of x.\n\n" | |
| 1089 | - "The result is between -pi/2 and pi/2.") | ||
| 1091 | + "The result is between -pi/2 and pi/2.", | ||
| 1092 | + "expected a number in range from -1 up to 1, got %s") | ||
| 1090 | 1093 | FUNC1(asinh, asinh, 0, | |
| 1091 | 1094 | "asinh($module, x, /)\n--\n\n" | |
| 1092 | 1095 | "Return the inverse hyperbolic sine of x.") | |
@@ -1147,9 +1150,10 @@ FUNC2(copysign, copysign, | |||
| 1147 | 1150 | "Return a float with the magnitude (absolute value) of x but the sign of y.\n\n" | |
| 1148 | 1151 | "On platforms that support signed zeros, copysign(1.0, -0.0)\n" | |
| 1149 | 1152 | "returns -1.0.\n") | |
| 1150 | - FUNC1(cos, cos, 0, | ||
| 1153 | + FUNC1D(cos, cos, 0, | ||
| 1151 | 1154 | "cos($module, x, /)\n--\n\n" | |
| 1152 | - "Return the cosine of x (measured in radians).") | ||
| 1155 | + "Return the cosine of x (measured in radians).", | ||
| 1156 | + "expected a finite input, got %s") | ||
| 1153 | 1157 | FUNC1(cosh, cosh, 1, | |
| 1154 | 1158 | "cosh($module, x, /)\n--\n\n" | |
| 1155 | 1159 | "Return the hyperbolic cosine of x.") | |
@@ -1213,33 +1217,37 @@ math_floor(PyObject *module, PyObject *number) | |||
| 1213 | 1217 | FUNC1AD(gamma, m_tgamma, | |
| 1214 | 1218 | "gamma($module, x, /)\n--\n\n" | |
| 1215 | 1219 | "Gamma function at x.", | |
| 1216 | - "expected a float or nonnegative integer, got %s") | ||
| 1217 | - FUNC1A(lgamma, m_lgamma, | ||
| 1220 | + "expected a noninteger or positive integer, got %s") | ||
| 1221 | + FUNC1AD(lgamma, m_lgamma, | ||
| 1218 | 1222 | "lgamma($module, x, /)\n--\n\n" | |
| 1219 | - "Natural logarithm of absolute value of Gamma function at x.") | ||
| 1220 | - FUNC1(log1p, m_log1p, 0, | ||
| 1223 | + "Natural logarithm of absolute value of Gamma function at x.", | ||
| 1224 | + "expected a noninteger or positive integer, got %s") | ||
| 1225 | + FUNC1D(log1p, m_log1p, 0, | ||
| 1221 | 1226 | "log1p($module, x, /)\n--\n\n" | |
| 1222 | 1227 | "Return the natural logarithm of 1+x (base e).\n\n" | |
| 1223 | - "The result is computed in a way which is accurate for x near zero.") | ||
| 1228 | + "The result is computed in a way which is accurate for x near zero.", | ||
| 1229 | + "expected argument value > -1, got %s") | ||
| 1224 | 1230 | FUNC2(remainder, m_remainder, | |
| 1225 | 1231 | "remainder($module, x, y, /)\n--\n\n" | |
| 1226 | 1232 | "Difference between x and the closest integer multiple of y.\n\n" | |
| 1227 | 1233 | "Return x - n*y where n*y is the closest integer multiple of y.\n" | |
| 1228 | 1234 | "In the case where x is exactly halfway between two multiples of\n" | |
| 1229 | 1235 | "y, the nearest even value of n is used. The result is always exact.") | |
| 1230 | - FUNC1(sin, sin, 0, | ||
| 1236 | + FUNC1D(sin, sin, 0, | ||
| 1231 | 1237 | "sin($module, x, /)\n--\n\n" | |
| 1232 | - "Return the sine of x (measured in radians).") | ||
| 1238 | + "Return the sine of x (measured in radians).", | ||
| 1239 | + "expected a finite input, got %s") | ||
| 1233 | 1240 | FUNC1(sinh, sinh, 1, | |
| 1234 | 1241 | "sinh($module, x, /)\n--\n\n" | |
| 1235 | 1242 | "Return the hyperbolic sine of x.") | |
| 1236 | 1243 | FUNC1D(sqrt, sqrt, 0, | |
| 1237 | 1244 | "sqrt($module, x, /)\n--\n\n" | |
| 1238 | 1245 | "Return the square root of x.", | |
| 1239 | 1246 | "expected a nonnegative input, got %s") | |
| 1240 | - FUNC1(tan, tan, 0, | ||
| 1247 | + FUNC1D(tan, tan, 0, | ||
| 1241 | 1248 | "tan($module, x, /)\n--\n\n" | |
| 1242 | - "Return the tangent of x (measured in radians).") | ||
| 1249 | + "Return the tangent of x (measured in radians).", | ||
| 1250 | + "expected a finite input, got %s") | ||
| 1243 | 1251 | FUNC1(tanh, tanh, 0, | |
| 1244 | 1252 | "tanh($module, x, /)\n--\n\n" | |
| 1245 | 1253 | "Return the hyperbolic tangent of x.") | |
| Back | FazBrowse Home | New Git URL |
0 commit comments