[Python-Dev] Why is nb_inplace_power ternary? (original) (raw)

Brett Cannon brett at python.org
Thu Feb 8 20:48:27 CET 2007


On 2/8/07, "Martin v. Löwis" <Martin.vonLoewis at hpi.uni-potsdam.de> wrote:

#1653736 reports that slotnbinplacepower has the wrong type: it should be a ternary function, but only is a binary. The proposed change is to make it ternary, and to invoke ipow with three arguments.

In researching this, I came to wonder why nbinplacepower is ternary in the first place. It is the implementation of foo **= bar (and that's its only use), so it ought to be binary. Historically, the reason probably is that it was copied from nbpower, which is ternary because it also implements pow()). So here is my proposed change: 1. For 2.5.1, rewrite slotnbinplacepower to raise an exception if the third argument is not None, and then invoke ipow with only one argument. 2. For 2.6, change the API to make nbinplacepower binary. Optionally, in 2.5, the exception could be added into other places as well, e.g. PyNumberInPlacePower and instanceipow (rather than invoking ipow with a third argument if its not None). Comments?

Seems reasonable to me. Is the argument of None passed in automatically somewhere? I think the 2.6 change is definitely good, just don't know if the exception is really needed. I realize the signature is off, but it doesn't hurt anyone at this point if it stayed wrong since obviously the semantics would be the same as they were.

-Brett



More information about the Python-Dev mailing list