@@ -173,7 +173,7 @@ impl PyType {
173
173
174
174
let mros = bases
175
175
. iter ( )
176
- . map ( |x| x. iter_mro ( ) . cloned ( ) . collect ( ) )
176
+ . map ( |x| x. iter_mro ( ) . map ( |x| x . to_owned ( ) ) . collect ( ) )
177
177
. collect ( ) ;
178
178
let mro = linearise_mro ( mros) ?;
179
179
@@ -247,7 +247,7 @@ impl PyType {
247
247
* slots. name . get_mut ( ) = Some ( String :: from ( name) ) ;
248
248
249
249
let bases = vec ! [ base. clone( ) ] ;
250
- let mro = base. iter_mro ( ) . cloned ( ) . collect ( ) ;
250
+ let mro = base. iter_mro ( ) . map ( |x| x . to_owned ( ) ) . collect ( ) ;
251
251
252
252
let new_type = PyRef :: new_ref (
253
253
PyType {
@@ -353,20 +353,20 @@ impl PyType {
353
353
}
354
354
}
355
355
356
- impl PyTypeRef {
356
+ impl Py < PyType > {
357
357
/// Determines if `subclass` is actually a subclass of `cls`, this doesn't call __subclasscheck__,
358
358
/// so only use this if `cls` is known to have not overridden the base __subclasscheck__ magic
359
359
/// method.
360
360
pub fn fast_issubclass ( & self , cls : & impl Borrow < crate :: PyObject > ) -> bool {
361
361
self . as_object ( ) . is ( cls. borrow ( ) ) || self . mro . iter ( ) . any ( |c| c. is ( cls. borrow ( ) ) )
362
362
}
363
363
364
- pub fn iter_mro ( & self ) -> impl Iterator < Item = & PyTypeRef > + DoubleEndedIterator {
365
- std:: iter:: once ( self ) . chain ( self . mro . iter ( ) )
364
+ pub fn iter_mro ( & self ) -> impl Iterator < Item = & Py < PyType > > + DoubleEndedIterator {
365
+ std:: iter:: once ( self ) . chain ( self . mro . iter ( ) . map ( |x| x . deref ( ) ) )
366
366
}
367
367
368
- pub fn iter_base_chain ( & self ) -> impl Iterator < Item = & PyTypeRef > {
369
- std:: iter:: successors ( Some ( self ) , |cls| cls. base . as_ref ( ) )
368
+ pub fn iter_base_chain ( & self ) -> impl Iterator < Item = & Py < PyType > > {
369
+ std:: iter:: successors ( Some ( self ) , |cls| cls. base . as_deref ( ) )
370
370
}
371
371
}
372
372
@@ -569,7 +569,7 @@ impl PyType {
569
569
570
570
#[ pymethod]
571
571
fn mro ( zelf : PyRef < Self > ) -> Vec < PyObjectRef > {
572
- zelf. iter_mro ( ) . map ( |cls| cls. clone ( ) . into ( ) ) . collect ( )
572
+ zelf. iter_mro ( ) . map ( |cls| cls. to_owned ( ) . into ( ) ) . collect ( )
573
573
}
574
574
575
575
#[ pymethod( magic) ]
@@ -588,7 +588,7 @@ impl PyType {
588
588
589
589
let is_type_type = metatype. is ( vm. ctx . types . type_type ) ;
590
590
if is_type_type && args. args . len ( ) == 1 && args. kwargs . is_empty ( ) {
591
- return Ok ( args. args [ 0 ] . class ( ) . clone ( ) . into ( ) ) ;
591
+ return Ok ( args. args [ 0 ] . class ( ) . to_owned ( ) . into ( ) ) ;
592
592
}
593
593
594
594
if args. args . len ( ) != 3 {
@@ -921,7 +921,7 @@ impl GetAttr for PyType {
921
921
if has_descr_set {
922
922
let descr_get = attr_class. mro_find_map ( |cls| cls. slots . descr_get . load ( ) ) ;
923
923
if let Some ( descr_get) = descr_get {
924
- let mcl = mcl. into_owned ( ) . into ( ) ;
924
+ let mcl = mcl. to_owned ( ) . into ( ) ;
925
925
return descr_get ( attr. clone ( ) , Some ( zelf. to_owned ( ) . into ( ) ) , Some ( mcl) , vm) ;
926
926
}
927
927
}
@@ -932,15 +932,13 @@ impl GetAttr for PyType {
932
932
if let Some ( ref attr) = zelf_attr {
933
933
let descr_get = attr. class ( ) . mro_find_map ( |cls| cls. slots . descr_get . load ( ) ) ;
934
934
if let Some ( descr_get) = descr_get {
935
- drop ( mcl) ;
936
935
return descr_get ( attr. clone ( ) , None , Some ( zelf. to_owned ( ) . into ( ) ) , vm) ;
937
936
}
938
937
}
939
938
940
939
if let Some ( cls_attr) = zelf_attr {
941
940
Ok ( cls_attr)
942
941
} else if let Some ( attr) = mcl_attr {
943
- drop ( mcl) ;
944
942
vm. call_if_get_descriptor ( attr, zelf. to_owned ( ) . into ( ) )
945
943
} else {
946
944
return Err ( attribute_error ( zelf, name_str. as_str ( ) , vm) ) ;
@@ -1007,7 +1005,7 @@ impl Callable for PyType {
1007
1005
}
1008
1006
}
1009
1007
1010
- fn find_base_dict_descr ( cls : & PyTypeRef , vm : & VirtualMachine ) -> Option < PyObjectRef > {
1008
+ fn find_base_dict_descr ( cls : & Py < PyType > , vm : & VirtualMachine ) -> Option < PyObjectRef > {
1011
1009
cls. iter_base_chain ( ) . skip ( 1 ) . find_map ( |cls| {
1012
1010
// TODO: should actually be some translation of:
1013
1011
// cls.slot_dictoffset != 0 && !cls.flags.contains(HEAPTYPE)
@@ -1021,12 +1019,11 @@ fn find_base_dict_descr(cls: &PyTypeRef, vm: &VirtualMachine) -> Option<PyObject
1021
1019
1022
1020
fn subtype_get_dict ( obj : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
1023
1021
// TODO: obj.class().as_pyref() need to be supported
1024
- let cls = obj. class ( ) . clone ( ) ;
1025
- let ret = match find_base_dict_descr ( & cls, vm) {
1026
- Some ( descr) => vm. call_get_descriptor ( descr, obj) . unwrap_or_else ( |_| {
1022
+ let ret = match find_base_dict_descr ( obj. class ( ) , vm) {
1023
+ Some ( descr) => vm. call_get_descriptor ( descr, obj) . unwrap_or_else ( |obj| {
1027
1024
Err ( vm. new_type_error ( format ! (
1028
1025
"this __dict__ descriptor does not support '{}' objects" ,
1029
- cls . name ( )
1026
+ obj . class ( )
1030
1027
) ) )
1031
1028
} ) ?,
1032
1029
None => object:: object_get_dict ( obj, vm) ?. into ( ) ,
@@ -1035,8 +1032,8 @@ fn subtype_get_dict(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult {
1035
1032
}
1036
1033
1037
1034
fn subtype_set_dict ( obj : PyObjectRef , value : PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
1038
- let cls = obj. class ( ) . clone ( ) ;
1039
- match find_base_dict_descr ( & cls, vm) {
1035
+ let cls = obj. class ( ) ;
1036
+ match find_base_dict_descr ( cls, vm) {
1040
1037
Some ( descr) => {
1041
1038
let descr_set = descr
1042
1039
. class ( )
@@ -1152,10 +1149,10 @@ fn calculate_meta_class(
1152
1149
let mut winner = metatype;
1153
1150
for base in bases {
1154
1151
let base_type = base. class ( ) ;
1155
- if winner. fast_issubclass ( & base_type) {
1152
+ if winner. fast_issubclass ( base_type) {
1156
1153
continue ;
1157
1154
} else if base_type. fast_issubclass ( & winner) {
1158
- winner = base_type. into_owned ( ) ;
1155
+ winner = base_type. to_owned ( ) ;
1159
1156
continue ;
1160
1157
}
1161
1158
0 commit comments