@@ -3,8 +3,8 @@ use crate::{
33 class:: PyClassImpl ,
44 convert:: ToPyObject ,
55 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 } ,
88 AsObject , Context , Py , PyObject , PyObjectRef , PyPayload , PyRef , PyResult , VirtualMachine ,
99} ;
1010
@@ -152,25 +152,26 @@ impl PyMappingProxy {
152152
153153 #[ pymethod( magic) ]
154154 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+ )
158160 }
159161
160162 #[ pymethod( magic) ]
161163 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+ ) ) )
163168 }
164169
170+ #[ pymethod( name = "__ror__" ) ]
165171 #[ pymethod( magic) ]
166172 fn or ( & self , args : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
167173 vm. _or ( self . copy ( vm) ?. as_ref ( ) , args. as_ref ( ) )
168174 }
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- }
174175}
175176
176177impl AsMapping for PyMappingProxy {
@@ -186,11 +187,18 @@ impl AsMapping for PyMappingProxy {
186187impl AsSequence for PyMappingProxy {
187188 const AS_SEQUENCE : PySequenceMethods = PySequenceMethods {
188189 contains : Some ( |seq, target, vm| Self :: sequence_downcast ( seq) . _contains ( target, vm) ) ,
189- length : Some ( |seq, vm| Self :: sequence_downcast ( seq) . len ( vm) ) ,
190190 ..PySequenceMethods :: NOT_IMPLEMENTED
191191 } ;
192192}
193193
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+
194202impl Iterable for PyMappingProxy {
195203 fn iter ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult {
196204 let obj = zelf. to_object ( vm) ?;
0 commit comments