@@ -3,8 +3,8 @@ use crate::{
3
3
class:: PyClassImpl ,
4
4
convert:: ToPyObject ,
5
5
function:: { ArgMapping , OptionalArg } ,
6
- protocol:: { PyMapping , PyMappingMethods , PySequence , PySequenceMethods } ,
7
- types:: { AsMapping , AsSequence , Constructor , Iterable } ,
6
+ protocol:: { PyMapping , PyMappingMethods , PyNumberMethods , PySequence , PySequenceMethods } ,
7
+ types:: { AsMapping , AsNumber , AsSequence , Constructor , Iterable } ,
8
8
AsObject , Context , Py , PyObject , PyObjectRef , PyPayload , PyRef , PyResult , VirtualMachine ,
9
9
} ;
10
10
@@ -152,25 +152,26 @@ impl PyMappingProxy {
152
152
153
153
#[ pymethod( magic) ]
154
154
fn reversed ( & self , vm : & VirtualMachine ) -> PyResult {
155
- let obj = self . to_object ( vm) ?;
156
- let reversed_method = vm. get_method ( obj, identifier ! ( vm, __reversed__) ) . unwrap ( ) ;
157
- vm. invoke ( & reversed_method?, ( ) )
155
+ vm. call_method (
156
+ self . to_object ( vm) ?. as_object ( ) ,
157
+ identifier ! ( vm, __reversed__) . as_str ( ) ,
158
+ ( ) ,
159
+ )
158
160
}
159
161
160
162
#[ pymethod( magic) ]
161
163
fn ior ( & self , _args : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
162
- Err ( vm. new_type_error ( "\" '|=' is not supported by %s; use '|' instead\" " . to_owned ( ) ) )
164
+ Err ( vm. new_type_error ( format ! (
165
+ "\" '|=' is not supported by {}; use '|' instead\" " ,
166
+ Self :: class( vm)
167
+ ) ) )
163
168
}
164
169
170
+ #[ pymethod( name = "__ror__" ) ]
165
171
#[ pymethod( magic) ]
166
172
fn or ( & self , args : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
167
173
vm. _or ( self . copy ( vm) ?. as_ref ( ) , args. as_ref ( ) )
168
174
}
169
-
170
- #[ pymethod( magic) ]
171
- fn ror ( & self , args : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
172
- vm. _or ( args. as_ref ( ) , self . copy ( vm) ?. as_ref ( ) )
173
- }
174
175
}
175
176
176
177
impl AsMapping for PyMappingProxy {
@@ -186,11 +187,18 @@ impl AsMapping for PyMappingProxy {
186
187
impl AsSequence for PyMappingProxy {
187
188
const AS_SEQUENCE : PySequenceMethods = PySequenceMethods {
188
189
contains : Some ( |seq, target, vm| Self :: sequence_downcast ( seq) . _contains ( target, vm) ) ,
189
- length : Some ( |seq, vm| Self :: sequence_downcast ( seq) . len ( vm) ) ,
190
190
..PySequenceMethods :: NOT_IMPLEMENTED
191
191
} ;
192
192
}
193
193
194
+ impl AsNumber for PyMappingProxy {
195
+ const AS_NUMBER : PyNumberMethods = PyNumberMethods {
196
+ or : Some ( |num, args, vm| Self :: number_downcast ( num) . or ( args. to_pyobject ( vm) , vm) ) ,
197
+ inplace_or : Some ( |num, args, vm| Self :: number_downcast ( num) . ior ( args. to_pyobject ( vm) , vm) ) ,
198
+ ..PyNumberMethods :: NOT_IMPLEMENTED
199
+ } ;
200
+ }
201
+
194
202
impl Iterable for PyMappingProxy {
195
203
fn iter ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult {
196
204
let obj = zelf. to_object ( vm) ?;
0 commit comments