@@ -5,6 +5,7 @@ use crate::{
5
5
exceptions:: PyBaseExceptionRef ,
6
6
function:: { ArgIterable , FuncArgs , KwArgs , OptionalArg } ,
7
7
iterator,
8
+ protocol:: PyMapping ,
8
9
slots:: {
9
10
AsMapping , Comparable , Hashable , Iterable , IteratorIterable , PyComparisonOp , PyIter ,
10
11
Unhashable ,
@@ -13,7 +14,7 @@ use crate::{
13
14
IdProtocol , IntoPyObject , ItemProtocol ,
14
15
PyArithmaticValue :: * ,
15
16
PyAttributes , PyClassDef , PyClassImpl , PyComparisonValue , PyContext , PyObjectRef , PyRef ,
16
- PyResult , PyValue , TryFromBorrowedObject , TypeProtocol ,
17
+ PyResult , PyValue , TypeProtocol ,
17
18
} ;
18
19
use crossbeam_utils:: atomic:: AtomicCell ;
19
20
use std:: fmt;
@@ -917,36 +918,3 @@ pub(crate) fn init(context: &PyContext) {
917
918
PyDictItemIterator :: extend_class ( context, & context. types . dict_itemiterator_type ) ;
918
919
PyDictReverseItemIterator :: extend_class ( context, & context. types . dict_reverseitemiterator_type ) ;
919
920
}
920
-
921
- #[ allow( clippy:: type_complexity) ]
922
- pub struct PyMapping {
923
- pub length : Option < fn ( PyObjectRef , & VirtualMachine ) -> PyResult < usize > > ,
924
- pub subscript : Option < fn ( PyObjectRef , PyObjectRef , & VirtualMachine ) -> PyResult > ,
925
- pub ass_subscript :
926
- Option < fn ( PyObjectRef , PyObjectRef , Option < PyObjectRef > , & VirtualMachine ) -> PyResult < ( ) > > ,
927
- }
928
-
929
- impl PyMapping {
930
- pub fn check ( cls : & PyObjectRef , vm : & VirtualMachine ) -> bool {
931
- if let Ok ( mapping) = PyMapping :: try_from_borrowed_object ( vm, cls) {
932
- mapping. subscript . is_some ( )
933
- } else {
934
- false
935
- }
936
- }
937
- }
938
-
939
- impl TryFromBorrowedObject for PyMapping {
940
- fn try_from_borrowed_object ( vm : & VirtualMachine , obj : & PyObjectRef ) -> PyResult < Self > {
941
- let obj_cls = obj. class ( ) ;
942
- for cls in obj_cls. iter_mro ( ) {
943
- if let Some ( f) = cls. slots . as_mapping . load ( ) {
944
- return f ( obj, vm) ;
945
- }
946
- }
947
- Err ( vm. new_type_error ( format ! (
948
- "a dict-like object is required, not '{}'" ,
949
- obj_cls. name( )
950
- ) ) )
951
- }
952
- }
0 commit comments