@@ -136,7 +136,6 @@ pub struct PyNumberMethods {
136
136
pub inplace_subtract : BinaryFunc ,
137
137
pub inplace_multiply : BinaryFunc ,
138
138
pub inplace_remainder : BinaryFunc ,
139
- pub inplace_divmod : BinaryFunc ,
140
139
pub inplace_power : BinaryFunc ,
141
140
pub inplace_lshift : BinaryFunc ,
142
141
pub inplace_rshift : BinaryFunc ,
@@ -182,7 +181,6 @@ impl PyNumberMethods {
182
181
inplace_subtract : AtomicCell :: new ( None ) ,
183
182
inplace_multiply : AtomicCell :: new ( None ) ,
184
183
inplace_remainder : AtomicCell :: new ( None ) ,
185
- inplace_divmod : AtomicCell :: new ( None ) ,
186
184
inplace_power : AtomicCell :: new ( None ) ,
187
185
inplace_lshift : AtomicCell :: new ( None ) ,
188
186
inplace_rshift : AtomicCell :: new ( None ) ,
@@ -197,8 +195,73 @@ impl PyNumberMethods {
197
195
matrix_multiply : AtomicCell :: new ( None ) ,
198
196
inplace_matrix_multiply : AtomicCell :: new ( None ) ,
199
197
} ;
198
+
199
+ pub fn get_binary_op ( & self , op_slot : & PyNumberBinaryOpSlot ) -> PyResult < & BinaryFunc > {
200
+ use PyNumberBinaryOpSlot :: * ;
201
+ let binary_op = match op_slot {
202
+ Add => & self . add ,
203
+ Subtract => & self . subtract ,
204
+ Multiply => & self . multiply ,
205
+ Remainder => & self . remainder ,
206
+ Divmod => & self . divmod ,
207
+ Power => & self . power ,
208
+ Lshift => & self . lshift ,
209
+ Rshift => & self . rshift ,
210
+ And => & self . and ,
211
+ Xor => & self . xor ,
212
+ Or => & self . or ,
213
+ InplaceAdd => & self . inplace_add ,
214
+ InplaceSubtract => & self . inplace_subtract ,
215
+ InplaceMultiply => & self . inplace_multiply ,
216
+ InplaceRemainder => & self . inplace_remainder ,
217
+ InplacePower => & self . inplace_power ,
218
+ InplaceLshift => & self . inplace_lshift ,
219
+ InplaceRshift => & self . inplace_rshift ,
220
+ InplaceAnd => & self . inplace_and ,
221
+ InplaceXor => & self . inplace_xor ,
222
+ InplaceOr => & self . inplace_or ,
223
+ FloorDivide => & self . floor_divide ,
224
+ TrueDivide => & self . true_divide ,
225
+ InplaceFloorDivide => & self . inplace_floor_divide ,
226
+ InplaceTrueDivide => & self . inplace_true_divide ,
227
+ MatrixMultiply => & self . matrix_multiply ,
228
+ InplaceMatrixMultiply => & self . inplace_matrix_multiply ,
229
+ } ;
230
+ Ok ( binary_op)
231
+ }
200
232
}
201
233
234
+ pub enum PyNumberBinaryOpSlot {
235
+ Add ,
236
+ Subtract ,
237
+ Multiply ,
238
+ Remainder ,
239
+ Divmod ,
240
+ Power ,
241
+ Lshift ,
242
+ Rshift ,
243
+ And ,
244
+ Xor ,
245
+ Or ,
246
+ InplaceAdd ,
247
+ InplaceSubtract ,
248
+ InplaceMultiply ,
249
+ InplaceRemainder ,
250
+ InplacePower ,
251
+ InplaceLshift ,
252
+ InplaceRshift ,
253
+ InplaceAnd ,
254
+ InplaceXor ,
255
+ InplaceOr ,
256
+ FloorDivide ,
257
+ TrueDivide ,
258
+ InplaceFloorDivide ,
259
+ InplaceTrueDivide ,
260
+ MatrixMultiply ,
261
+ InplaceMatrixMultiply ,
262
+ }
263
+
264
+ #[ derive( Copy , Clone ) ]
202
265
pub struct PyNumber < ' a > {
203
266
pub obj : & ' a PyObject ,
204
267
methods : & ' a PyNumberMethods ,
@@ -224,6 +287,10 @@ impl PyNumber<'_> {
224
287
self . methods
225
288
}
226
289
290
+ pub fn get_binary_op ( & self , op_slot : & PyNumberBinaryOpSlot ) -> PyResult < & BinaryFunc > {
291
+ self . methods ( ) . get_binary_op ( op_slot)
292
+ }
293
+
227
294
// PyNumber_Check
228
295
pub fn check ( obj : & PyObject ) -> bool {
229
296
let Some ( methods) = Self :: find_methods ( obj) else {
0 commit comments