@@ -240,6 +240,53 @@ func SetAttr(self Object, keyObj Object, value Object) Object{
240240panic (ExceptionNewf (TypeError , "attribute name must be string, not '%s'" , self .Type ().Name ))
241241}
242242
243+ // DeleteAttrString
244+ func DeleteAttrString (self Object , key string ){
245+ // First look in type's dictionary etc for a property that could
246+ // be set - do this before looking in the instance dictionary
247+ deleter := self .Type ().NativeGetAttrOrNil (key )
248+ if deleter != nil {
249+ // Call __set__ which writes properties etc
250+ if I , ok := deleter .(I__delete__ ); ok {
251+ I .M__delete__ (self )
252+ return
253+ }
254+ }
255+
256+ // If we have __delattr__ then use that
257+ if I , ok := self .(I__delattr__ ); ok {
258+ I .M__delattr__ (key )
259+ return
260+ } else if _ , ok := TypeCall1 (self , "__delattr__" , String (key )); ok {
261+ return
262+ }
263+
264+ // Otherwise delete the attribute from the instance dictionary
265+ // if possible
266+ if I , ok := self .(IGetDict ); ok {
267+ dict := I .GetDict ()
268+ if dict == nil {
269+ panic (ExceptionNewf (SystemError , "nil Dict in %s" , self .Type ().Name ))
270+ }
271+ if _ , ok := dict [key ]; ok {
272+ delete (dict , key )
273+ return
274+ }
275+ }
276+
277+ // If not blow up
278+ panic (ExceptionNewf (AttributeError , "'%s' object has no attribute '%s'" , self .Type ().Name , key ))
279+ }
280+
281+ // DeleteAttr
282+ func DeleteAttr (self Object , keyObj Object ){
283+ if key , ok := keyObj .(String ); ok {
284+ DeleteAttrString (self , string (key ))
285+ return
286+ }
287+ panic (ExceptionNewf (TypeError , "attribute name must be string, not '%s'" , self .Type ().Name ))
288+ }
289+
243290// Call __next__ for the python object
244291func Next (self Object ) Object {
245292if I , ok := self .(I__next__ ); ok {
0 commit comments