From: Mark Dickinson Date: Fri, 11 Apr 2014 18:34:40 +0000 (-0400) Subject: Issue #21193: Make (e.g.,) pow(2, -3, 5) raise ValueError rather than TypeError.... X-Git-Tag: v3.5.0a1~1907 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0c346d827d38917c4ab4b7679e223f163aec4724;p=thirdparty%2FPython%2Fcpython.git Issue #21193: Make (e.g.,) pow(2, -3, 5) raise ValueError rather than TypeError. Patch by Josh Rosenberg. --- diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index b561a6f73adc..9d2725e59231 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -1085,7 +1085,7 @@ class BuiltinTest(unittest.TestCase): if isinstance(x, float) or \ isinstance(y, float) or \ isinstance(z, float): - self.assertRaises(TypeError, pow, x, y, z) + self.assertRaises(ValueError, pow, x, y, z) else: self.assertAlmostEqual(pow(x, y, z), 24.0) diff --git a/Misc/ACKS b/Misc/ACKS index f1ed07c0e752..437aa461dc39 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1111,6 +1111,7 @@ Armin Ronacher Case Roole Timothy Roscoe Erik Rose +Josh Rosenberg Jim Roskind Brian Rosner Guido van Rossum diff --git a/Misc/NEWS b/Misc/NEWS index dc61927775d2..0b558727ba1c 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Release date: TBA Core and Builtins ----------------- +- Issue #21193: pow(a, b, c) now raises ValueError rather than TypeError when b + is negative. Patch by Josh Rosenberg. + - PEP 465 and Issue #21176: Add the '@' operator for matrix multiplication. - Issue #21134: Fix segfault when str is called on an uninitialized diff --git a/Objects/longobject.c b/Objects/longobject.c index 7036c0ea4ad8..b749fd3d2df7 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -3841,7 +3841,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x) if (Py_SIZE(b) < 0) { /* if exponent is negative */ if (c) { - PyErr_SetString(PyExc_TypeError, "pow() 2nd argument " + PyErr_SetString(PyExc_ValueError, "pow() 2nd argument " "cannot be negative when 3rd argument specified"); goto Error; }