https://github.com/python/cpython/commit/0b75b7338d3a85199396404106aa011559c9c250
commit: 0b75b7338d3a85199396404106aa011559c9c250
branch: main
author: Wulian233 <[email protected]>
committer: markshannon <[email protected]>
date: 2026-05-06T13:59:08+01:00
summary:

gh-100239: specialize mixed int/float inplace binary ops (GH-149413)

files:
M Lib/test/test_opcache.py
M Python/specialize.c

diff --git a/Lib/test/test_opcache.py b/Lib/test/test_opcache.py
index bd97b0b4d61474..7946550ec0db63 100644
--- a/Lib/test/test_opcache.py
+++ b/Lib/test/test_opcache.py
@@ -1419,6 +1419,30 @@ def binary_op_add_extend():
                 self.assertEqual(c, 2.0)
                 c = b / a
                 self.assertEqual(c, 0.5)
+                c = a
+                c += b
+                self.assertEqual(c, 9.0)
+                c = b
+                c += a
+                self.assertEqual(c, 9.0)
+                c = a
+                c -= b
+                self.assertEqual(c, 3.0)
+                c = b
+                c -= a
+                self.assertEqual(c, -3.0)
+                c = a
+                c *= b
+                self.assertEqual(c, 18.0)
+                c = b
+                c *= a
+                self.assertEqual(c, 18.0)
+                c = a
+                c /= b
+                self.assertEqual(c, 2.0)
+                c = b
+                c /= a
+                self.assertEqual(c, 0.5)
 
         binary_op_add_extend()
         self.assert_specialized(binary_op_add_extend, "BINARY_OP_EXTEND")
diff --git a/Python/specialize.c b/Python/specialize.c
index c54807931f2326..459e69de5709b8 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -2278,12 +2278,20 @@ static _PyBinaryOpSpecializationDescr 
binaryop_extend_descrs[] = {
     {NB_SUBTRACT, float_compactlong_guard, float_compactlong_subtract, 
&PyFloat_Type, 1, NULL, NULL},
     {NB_TRUE_DIVIDE, nonzero_float_compactlong_guard, 
float_compactlong_true_div, &PyFloat_Type, 1, NULL, NULL},
     {NB_MULTIPLY, float_compactlong_guard, float_compactlong_multiply, 
&PyFloat_Type, 1, NULL, NULL},
+    {NB_INPLACE_ADD, float_compactlong_guard, float_compactlong_add, 
&PyFloat_Type, 1, NULL, NULL},
+    {NB_INPLACE_SUBTRACT, float_compactlong_guard, float_compactlong_subtract, 
&PyFloat_Type, 1, NULL, NULL},
+    {NB_INPLACE_TRUE_DIVIDE, nonzero_float_compactlong_guard, 
float_compactlong_true_div, &PyFloat_Type, 1, NULL, NULL},
+    {NB_INPLACE_MULTIPLY, float_compactlong_guard, float_compactlong_multiply, 
&PyFloat_Type, 1, NULL, NULL},
 
     /* long-float arithmetic: guards also check NaN and compactness. */
     {NB_ADD, compactlong_float_guard, compactlong_float_add, &PyFloat_Type, 1, 
NULL, NULL},
     {NB_SUBTRACT, compactlong_float_guard, compactlong_float_subtract, 
&PyFloat_Type, 1, NULL, NULL},
     {NB_TRUE_DIVIDE, nonzero_compactlong_float_guard, 
compactlong_float_true_div, &PyFloat_Type, 1, NULL, NULL},
     {NB_MULTIPLY, compactlong_float_guard, compactlong_float_multiply, 
&PyFloat_Type, 1, NULL, NULL},
+    {NB_INPLACE_ADD, compactlong_float_guard, compactlong_float_add, 
&PyFloat_Type, 1, NULL, NULL},
+    {NB_INPLACE_SUBTRACT, compactlong_float_guard, compactlong_float_subtract, 
&PyFloat_Type, 1, NULL, NULL},
+    {NB_INPLACE_TRUE_DIVIDE, nonzero_compactlong_float_guard, 
compactlong_float_true_div, &PyFloat_Type, 1, NULL, NULL},
+    {NB_INPLACE_MULTIPLY, compactlong_float_guard, compactlong_float_multiply, 
&PyFloat_Type, 1, NULL, NULL},
 
     /* list-list concatenation: _PyList_Concat always allocates a new list */
     {NB_ADD, NULL, _PyList_Concat, &PyList_Type, 1, &PyList_Type, 
&PyList_Type},

_______________________________________________
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