Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e5680f

Browse files
committed
For some reason (probably cut and paste), __ipow__ for new-style
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): ...
1 parent 13b1a5c commit 6e5680f

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

Lib/test/test_descr.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3306,6 +3306,16 @@ def __rmul__(self, other):
33063306
vereq(2*a, "rmul")
33073307
vereq(2.2*a, "rmul")
33083308

3309+
def testipow():
3310+
# [SF bug 620179]
3311+
if verbose:
3312+
print "Testing correct invocation of __ipow__..."
3313+
class C(object):
3314+
def __ipow__(self, other):
3315+
pass
3316+
a = C()
3317+
a **= 2
3318+
33093319
def do_this_first():
33103320
if verbose:
33113321
print "Testing SF bug 551412 ..."
@@ -3401,6 +3411,7 @@ def test_main():
34013411
slottrash()
34023412
slotmultipleinheritance()
34033413
testrmul()
3414+
testipow()
34043415
if verbose: print "All OK"
34053416

34063417
if __name__ == "__main__":

Objects/typeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3399,7 +3399,7 @@ SLOT1(slot_nb_inplace_subtract, "__isub__", PyObject *, "O")
33993399
SLOT1(slot_nb_inplace_multiply, "__imul__", PyObject *, "O")
34003400
SLOT1(slot_nb_inplace_divide, "__idiv__", PyObject *, "O")
34013401
SLOT1(slot_nb_inplace_remainder, "__imod__", PyObject *, "O")
3402-
SLOT2(slot_nb_inplace_power, "__ipow__", PyObject *, PyObject *, "OO")
3402+
SLOT1(slot_nb_inplace_power, "__ipow__", PyObject *, "O")
34033403
SLOT1(slot_nb_inplace_lshift, "__ilshift__", PyObject *, "O")
34043404
SLOT1(slot_nb_inplace_rshift, "__irshift__", PyObject *, "O")
34053405
SLOT1(slot_nb_inplace_and, "__iand__", PyObject *, "O")
@@ -4038,7 +4038,7 @@ static slotdef slotdefs[] = {
40384038
IBSLOT("__imod__", nb_inplace_remainder, slot_nb_inplace_remainder,
40394039
wrap_binaryfunc, "%"),
40404040
IBSLOT("__ipow__", nb_inplace_power, slot_nb_inplace_power,
4041-
wrap_ternaryfunc, "**"),
4041+
wrap_binaryfunc, "**"),
40424042
IBSLOT("__ilshift__", nb_inplace_lshift, slot_nb_inplace_lshift,
40434043
wrap_binaryfunc, "<<"),
40444044
IBSLOT("__irshift__", nb_inplace_rshift, slot_nb_inplace_rshift,

0 commit comments

Comments
 (0)