https://github.com/python/cpython/commit/cfe41037eb5293a051846ddc0b4afdb7a5f60540
commit: cfe41037eb5293a051846ddc0b4afdb7a5f60540
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2025-02-17T00:07:10Z
summary:

gh-86069: Add more PyNumber_InPlacePower() tests (GH-130111)

Test it with the third argument.

files:
M Lib/test/test_capi/test_number.py

diff --git a/Lib/test/test_capi/test_number.py 
b/Lib/test/test_capi/test_number.py
index 04f85d2395083a..b915dee37c7ca6 100644
--- a/Lib/test/test_capi/test_number.py
+++ b/Lib/test/test_capi/test_number.py
@@ -205,8 +205,9 @@ def test_misc_multiply(self):
         self.assertRaises(MemoryError, inplacemultiply, [1, 2], 
PY_SSIZE_T_MAX//2 + 1)
 
     def test_misc_power(self):
-        # PyNumber_Power()
+        # PyNumber_Power(), PyNumber_InPlacePower()
         power = _testcapi.number_power
+        inplacepower = _testcapi.number_inplacepower
 
         class HasPow(WithDunder):
             methname = '__pow__'
@@ -216,6 +217,39 @@ class HasPow(WithDunder):
         self.assertRaises(TypeError, power, 4, 11, 1.25)
         self.assertRaises(TypeError, power, 4, 11, 
HasPow.with_val(NotImplemented))
         self.assertRaises(TypeError, power, 4, 11, object())
+        self.assertEqual(inplacepower(4, 11, 5), pow(4, 11, 5))
+        self.assertRaises(TypeError, inplacepower, 4, 11, 1.25)
+        self.assertRaises(TypeError, inplacepower, 4, 11, object())
+
+        class X:
+            def __pow__(*args):
+                return args
+
+        x = X()
+        self.assertEqual(power(x, 11), (x, 11))
+        self.assertEqual(inplacepower(x, 11), (x, 11))
+        self.assertEqual(power(x, 11, 5), (x, 11, 5))
+        self.assertEqual(inplacepower(x, 11, 5), (x, 11, 5))
+
+        class X:
+            def __rpow__(*args):
+                return args
+
+        x = X()
+        self.assertEqual(power(4, x), (x, 4))
+        self.assertEqual(inplacepower(4, x), (x, 4))
+        # XXX: Three-arg power doesn't use __rpow__.
+        self.assertRaises(TypeError, power, 4, x, 5)
+        self.assertRaises(TypeError, inplacepower, 4, x, 5)
+
+        class X:
+            def __ipow__(*args):
+                return args
+
+        x = X()
+        self.assertEqual(inplacepower(x, 11), (x, 11))
+        # XXX: In-place power doesn't pass the third arg to __ipow__.
+        self.assertEqual(inplacepower(x, 11, 5), (x, 11))
 
     def test_long(self):
         # Test PyNumber_Long()

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to