[Python-Dev] Why is nb_inplace_power ternary?

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 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?
>

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