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

"Martin v. Löwis" Martin.vonLoewis at hpi.uni-potsdam.de
Thu Feb 8 10:49:38 CET 2007


#1653736 reports that slot_nb_inplace_power 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 nb_inplace_power 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 nb_power, which is ternary because it also implements pow()).

So here is my proposed change:

  1. For 2.5.1, rewrite slot_nb_inplace_power 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 nb_inplace_power binary.

Optionally, in 2.5, the exception could be added into other places as well, e.g. PyNumber_InPlacePower and instance_ipow (rather than invoking ipow with a third argument if its not None).

Comments?

Regards, Martin



More information about the Python-Dev mailing list