]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
For some reason (probably cut and paste), __ipow__ for new-style
authorGuido van Rossum <guido@python.org>
Tue, 15 Oct 2002 01:01:53 +0000 (01:01 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 15 Oct 2002 01:01:53 +0000 (01:01 +0000)
classes was called with three arguments.  This makes no sense, there's
no way to pass in the "modulo" 3rd argument as for __pow__, and
classic classes don't do this.  [SF bug 620179]

I don't want to backport this to 2.2.2, because it could break
existing code that has developed a work-around.  Code in 2.2.2 that
wants to use __ipow__ and wants to be forward compatible with 2.3
should be written like this:

  def __ipow__(self, exponent, modulo=None):
      ...

Lib/test/test_descr.py
Objects/typeobject.c

index 0c7def14fe21feef9a7d13abe0051299f938d54b..c9bd1cd7d43d7534ce36046dc2fc5ad4d8acf48c 100644 (file)
@@ -3306,6 +3306,16 @@ def testrmul():
     vereq(2*a, "rmul")
     vereq(2.2*a, "rmul")
 
+def testipow():
+    # [SF bug 620179]
+    if verbose:
+        print "Testing correct invocation of __ipow__..."
+    class C(object):
+        def __ipow__(self, other):
+            pass
+    a = C()
+    a **= 2
+
 def do_this_first():
     if verbose:
         print "Testing SF bug 551412 ..."
@@ -3401,6 +3411,7 @@ def test_main():
     slottrash()
     slotmultipleinheritance()
     testrmul()
+    testipow()
     if verbose: print "All OK"
 
 if __name__ == "__main__":
index e11b87f62001b8e46643d19fcdbf57eeefa4119d..ed5b82951ae163eb000c3d2067dd7d571c701be9 100644 (file)
@@ -3399,7 +3399,7 @@ SLOT1(slot_nb_inplace_subtract, "__isub__", PyObject *, "O")
 SLOT1(slot_nb_inplace_multiply, "__imul__", PyObject *, "O")
 SLOT1(slot_nb_inplace_divide, "__idiv__", PyObject *, "O")
 SLOT1(slot_nb_inplace_remainder, "__imod__", PyObject *, "O")
-SLOT2(slot_nb_inplace_power, "__ipow__", PyObject *, PyObject *, "OO")
+SLOT1(slot_nb_inplace_power, "__ipow__", PyObject *, "O")
 SLOT1(slot_nb_inplace_lshift, "__ilshift__", PyObject *, "O")
 SLOT1(slot_nb_inplace_rshift, "__irshift__", PyObject *, "O")
 SLOT1(slot_nb_inplace_and, "__iand__", PyObject *, "O")
@@ -4038,7 +4038,7 @@ static slotdef slotdefs[] = {
        IBSLOT("__imod__", nb_inplace_remainder, slot_nb_inplace_remainder,
               wrap_binaryfunc, "%"),
        IBSLOT("__ipow__", nb_inplace_power, slot_nb_inplace_power,
-              wrap_ternaryfunc, "**"),
+              wrap_binaryfunc, "**"),
        IBSLOT("__ilshift__", nb_inplace_lshift, slot_nb_inplace_lshift,
               wrap_binaryfunc, "<<"),
        IBSLOT("__irshift__", nb_inplace_rshift, slot_nb_inplace_rshift,