@@ -6,10 +6,10 @@ use crate::{
6
6
builtins:: { PyFrozenSet , PyStr , PyStrRef , PyTuple , PyTupleRef , PyType } ,
7
7
class:: PyClassImpl ,
8
8
common:: hash,
9
- convert:: ToPyObject ,
9
+ convert:: { ToPyObject , ToPyResult } ,
10
10
function:: PyComparisonValue ,
11
- protocol:: PyMappingMethods ,
12
- types:: { AsMapping , Comparable , GetAttr , Hashable , PyComparisonOp } ,
11
+ protocol:: { PyMappingMethods , PyNumberMethods } ,
12
+ types:: { AsMapping , AsNumber , Comparable , GetAttr , Hashable , PyComparisonOp } ,
13
13
AsObject , Context , Py , PyObject , PyObjectRef , PyPayload , PyRef , PyResult , TryFromObject ,
14
14
VirtualMachine ,
15
15
} ;
@@ -35,7 +35,7 @@ impl PyPayload for PyUnion {
35
35
}
36
36
}
37
37
38
- #[ pyclass( with( Hashable , Comparable , AsMapping ) , flags ( BASETYPE ) ) ]
38
+ #[ pyclass( flags ( BASETYPE ) , with( Hashable , Comparable , AsMapping , AsNumber ) ) ]
39
39
impl PyUnion {
40
40
pub fn new ( args : PyTupleRef , vm : & VirtualMachine ) -> Self {
41
41
let parameters = make_parameters ( & args, vm) ;
@@ -255,6 +255,18 @@ impl AsMapping for PyUnion {
255
255
}
256
256
}
257
257
258
+ impl AsNumber for PyUnion {
259
+ fn as_number ( ) -> & ' static PyNumberMethods {
260
+ static AS_NUMBER : Lazy < PyNumberMethods > = Lazy :: new ( || PyNumberMethods {
261
+ or : atomic_func ! ( |num, other, vm| {
262
+ PyUnion :: or( num. obj. to_owned( ) , other. to_owned( ) , vm) . to_pyresult( vm)
263
+ } ) ,
264
+ ..PyNumberMethods :: NOT_IMPLEMENTED
265
+ } ) ;
266
+ & AS_NUMBER
267
+ }
268
+ }
269
+
258
270
impl Comparable for PyUnion {
259
271
fn cmp (
260
272
zelf : & crate :: Py < Self > ,
0 commit comments