Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python ipow : how to use the third argument?

In the official python documentation in the Data model section, the __ipow__ method is defined as:

object.__ipow__(self, other[, modulo])

Then, the documentation explains that These methods are called to implement the augmented arithmetic assignments (**= for __ipow__)

But what is the syntax of **= that allows to use the modulo argument ?

like image 379
Xoff Avatar asked Oct 31 '14 22:10

Xoff


1 Answers

The third argument is there just for symmetry with __pow__.

The argument was included in the original 'add in-place operator equivalents' commit but there is no support to use it from Python code, other than calling the __ipow__ method directly.

For example, the INPLACE_POWER opcode handling passes in None as the third argument:

case INPLACE_POWER:
    w = POP();
    v = TOP();
    x = PyNumber_InPlacePower(v, w, Py_None);
    Py_DECREF(v);
    Py_DECREF(w);
    SET_TOP(x);
    if (x != NULL) continue;
    break;

Most likely it is there to make implementing __ipow__ as an alias for __pow__ trivial even from C code.

like image 177
Martijn Pieters Avatar answered Nov 01 '22 10:11

Martijn Pieters