[Python-Dev] Why is nb_inplace_power ternary?

Brett Cannon brett at python.org
Fri Feb 9 19:27:51 CET 2007


On 2/9/07, "Martin v. Löwis" <Martin.vonLoewis at hpi.uni-potsdam.de> wrote:
> Brett Cannon schrieb:
> > Seems reasonable to me.  Is the argument of None passed in
> > automatically somewhere?
>
> There are few callers of nb_inplace_power at all (AFAICT, only
> PyNumber_InPlacePower); in turn, PyNumber_InPlacePower is called
> with the implicit Py_None always:
> - ceval.c, for INPLACE_POWER (which is binary)
> - operator.ipow (which is also binary)
> - class.c, from bin_inplace_power, which in turn is called from
>    instance_ipow if the instance's 3rd argument to
>    nb_inplace_power is Py_None (if there is a non-None third
>    argument, instance_ipow invokes __ipow__ with three arguments
>    if __ipow__ is defined, else it invokes __pow__ with three
>    arguments)
>
> The only case I could find where a third argument is non-None
> is when the builtin pow() is invoked, which then invokes nb_power
> (but not nb_inplace_power) with three arguments.
>

Well then explicitly ignoring the object makes sense to me.  While I
am personally fine with raising the exception, erring on the side of
caution as Raymond is suggesting wouldn't hurt either.

-Brett


More information about the Python-Dev mailing list