@@ -200,6 +200,23 @@ impl PyClassRef {
200
200
Ok ( ( ) )
201
201
}
202
202
203
+ fn del_attr ( self , attr_name : PyStringRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
204
+ if let Some ( attr) = class_get_attr ( & self . class ( ) , attr_name. as_str ( ) ) {
205
+ if let Some ( ref descriptor) = class_get_attr ( & attr. class ( ) , "__delete__" ) {
206
+ return vm
207
+ . invoke ( descriptor, vec ! [ attr, self . into_object( ) ] )
208
+ . map ( |_| ( ) ) ;
209
+ }
210
+ }
211
+
212
+ if let Some ( _) = class_get_attr ( & self , attr_name. as_str ( ) ) {
213
+ self . attributes . borrow_mut ( ) . remove ( attr_name. as_str ( ) ) ;
214
+ Ok ( ( ) )
215
+ } else {
216
+ Err ( vm. new_attribute_error ( attr_name. as_str ( ) . to_string ( ) ) )
217
+ }
218
+ }
219
+
203
220
// This is used for class initialisation where the vm is not yet available.
204
221
pub fn set_str_attr < V : Into < PyObjectRef > > ( & self , attr_name : & str , value : V ) {
205
222
self . attributes
@@ -256,8 +273,8 @@ pub fn init(ctx: &PyContext) {
256
273
"__prepare__" => ctx. new_rustfunc( PyClassRef :: prepare) ,
257
274
"__getattribute__" => ctx. new_rustfunc( PyClassRef :: getattribute) ,
258
275
"__setattr__" => ctx. new_rustfunc( PyClassRef :: set_attr) ,
276
+ "__delattr__" => ctx. new_rustfunc( PyClassRef :: del_attr) ,
259
277
"__subclasses__" => ctx. new_rustfunc( PyClassRef :: subclasses) ,
260
- "__getattribute__" => ctx. new_rustfunc( PyClassRef :: getattribute) ,
261
278
"__instancecheck__" => ctx. new_rustfunc( PyClassRef :: instance_check) ,
262
279
"__subclasscheck__" => ctx. new_rustfunc( PyClassRef :: subclass_check) ,
263
280
"__doc__" => ctx. new_str( type_doc. to_string( ) ) ,
0 commit comments