@@ -29,7 +29,7 @@ func init() {
29
29
// py.MustNewMethod("callable", builtin_callable, 0, callable_doc),
30
30
py .MustNewMethod ("chr" , builtin_chr , 0 , chr_doc ),
31
31
py .MustNewMethod ("compile" , builtin_compile , 0 , compile_doc ),
32
- // py.MustNewMethod("delattr", builtin_delattr, 0, delattr_doc),
32
+ py .MustNewMethod ("delattr" , builtin_delattr , 0 , delattr_doc ),
33
33
// py.MustNewMethod("dir", builtin_dir, 0, dir_doc),
34
34
py .MustNewMethod ("divmod" , builtin_divmod , 0 , divmod_doc ),
35
35
py .MustNewMethod ("eval" , py .InternalMethodEval , 0 , eval_doc ),
@@ -633,6 +633,27 @@ func source_as_string(cmd py.Object, funcname, what string /*, PyCompilerFlags *
633
633
// return nil;
634
634
}
635
635
636
+ const delattr_doc = `Deletes the named attribute from the given object.
637
+
638
+ delattr(x, 'y') is equivalent to "del x.y"
639
+ `
640
+
641
+ func builtin_delattr (self py.Object , args py.Tuple ) (py.Object , error ) {
642
+ var v py.Object
643
+ var name py.Object
644
+
645
+ err := py .UnpackTuple (args , nil , "delattr" , 2 , 2 , & v , & name )
646
+ if err != nil {
647
+ return nil , err
648
+ }
649
+
650
+ err = py .DeleteAttr (v , name )
651
+ if err != nil {
652
+ return nil , err
653
+ }
654
+ return py .None , nil
655
+ }
656
+
636
657
const compile_doc = `compile(source, filename, mode[, flags[, dont_inherit]]) -> code object
637
658
638
659
Compile the source string (a Python module, statement or expression)
0 commit comments