[issue21193] pow(a, b, c) should not raise TypeError when b is negative and c is provided

Mark Dickinson report at bugs.python.org
Thu Apr 10 15:49:29 CEST 2014


Mark Dickinson added the comment:

I was wondering how the TypeError got there in the first place.  Diving into the history is instructive: changeset cdfdd5359411 modified the exception message:

taniyama:cpython mdickinson$ hg log -r19719
changeset:   19719:cdfdd5359411
branch:      legacy-trunk
user:        Tim Peters <tim.peters at gmail.com>
date:        Wed Sep 05 06:24:58 2001 +0000
summary:     Make the error msgs in our pow() implementations consistent.

Before that change, the code looked like this:

	if (x != Py_None) {
		PyErr_SetString(PyExc_TypeError, "integer pow() arg "
		     "3 must not be specified when arg 2 is < 0");
		return NULL;
	}

>From that point of view the TypeError makes more sense: it's complaining about the wrong number of arguments rather than the negative value.  The current message changes the perspective, and I agree that ValueError makes more sense.

Tim: any objections to changing the exception type from TypeError to ValueError for Python 3.5?

I'd prefer not to change it for 2.7 or 3.4: there's an (admittedly probably quite low) risk of code breakage, and little real gain to offset that breakage.

----------
nosy: +tim.peters

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21193>
_______________________________________


More information about the Python-bugs-list mailing list