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