@@ -12,8 +12,8 @@ use crate::format::FormatSpec;
12
12
use crate :: function:: { OptionalArg , OptionalOption } ;
13
13
use crate :: pyhash;
14
14
use crate :: pyobject:: {
15
- IntoPyObject , PyClassImpl , PyContext , PyObjectRef , PyRef , PyResult , PyValue , TryFromObject ,
16
- TypeProtocol ,
15
+ IntoPyObject , PyArithmaticValue :: * , PyClassImpl , PyComparisonValue , PyContext , PyObjectRef ,
16
+ PyRef , PyResult , PyValue , TryFromObject , TypeProtocol ,
17
17
} ;
18
18
use crate :: vm:: VirtualMachine ;
19
19
@@ -196,19 +196,18 @@ impl PyFloat {
196
196
float_op : F ,
197
197
int_op : G ,
198
198
vm : & VirtualMachine ,
199
- ) -> PyObjectRef
199
+ ) -> PyComparisonValue
200
200
where
201
201
F : Fn ( f64 , f64 ) -> bool ,
202
202
G : Fn ( f64 , & BigInt ) -> bool ,
203
203
{
204
- let result = if let Some ( other) = other. payload_if_subclass :: < PyFloat > ( vm) {
205
- float_op ( self . value , other. value )
204
+ if let Some ( other) = other. payload_if_subclass :: < PyFloat > ( vm) {
205
+ Implemented ( float_op ( self . value , other. value ) )
206
206
} else if let Some ( other) = other. payload_if_subclass :: < PyInt > ( vm) {
207
- int_op ( self . value , other. as_bigint ( ) )
207
+ Implemented ( int_op ( self . value , other. as_bigint ( ) ) )
208
208
} else {
209
- return vm. ctx . not_implemented ( ) ;
210
- } ;
211
- vm. ctx . new_bool ( result)
209
+ NotImplemented
210
+ }
212
211
}
213
212
214
213
#[ pymethod( name = "__format__" ) ]
@@ -222,22 +221,22 @@ impl PyFloat {
222
221
}
223
222
224
223
#[ pymethod( name = "__eq__" ) ]
225
- fn eq ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyObjectRef {
226
- self . cmp ( other, |a, b| a == b, |a , b| int_eq ( a , b ) , vm)
224
+ fn eq ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyComparisonValue {
225
+ self . cmp ( other, |a, b| a == b, int_eq, vm)
227
226
}
228
227
229
228
#[ pymethod( name = "__ne__" ) ]
230
- fn ne ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyObjectRef {
231
- self . cmp ( other, |a , b| a != b , |a , b| ! int_eq ( a , b ) , vm )
229
+ fn ne ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyComparisonValue {
230
+ self . eq ( other, vm ) . map ( |v| !v )
232
231
}
233
232
234
233
#[ pymethod( name = "__lt__" ) ]
235
- fn lt ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyObjectRef {
236
- self . cmp ( other, |a, b| a < b, |a , b| inner_lt_int ( a , b ) , vm)
234
+ fn lt ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyComparisonValue {
235
+ self . cmp ( other, |a, b| a < b, inner_lt_int, vm)
237
236
}
238
237
239
238
#[ pymethod( name = "__le__" ) ]
240
- fn le ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyObjectRef {
239
+ fn le ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyComparisonValue {
241
240
self . cmp (
242
241
other,
243
242
|a, b| a <= b,
@@ -253,12 +252,12 @@ impl PyFloat {
253
252
}
254
253
255
254
#[ pymethod( name = "__gt__" ) ]
256
- fn gt ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyObjectRef {
257
- self . cmp ( other, |a, b| a > b, |a , b| inner_gt_int ( a , b ) , vm)
255
+ fn gt ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyComparisonValue {
256
+ self . cmp ( other, |a, b| a > b, inner_gt_int, vm)
258
257
}
259
258
260
259
#[ pymethod( name = "__ge__" ) ]
261
- fn ge ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyObjectRef {
260
+ fn ge ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyComparisonValue {
262
261
self . cmp (
263
262
other,
264
263
|a, b| a >= b,
0 commit comments