@@ -125,7 +125,14 @@ fn builtin_compile(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
125
125
compile:: compile ( vm, & source, mode, None )
126
126
}
127
127
128
- // builtin_delattr
128
+ fn builtin_delattr ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
129
+ arg_check ! (
130
+ vm,
131
+ args,
132
+ required = [ ( obj, None ) , ( attr, Some ( vm. ctx. str_type( ) ) ) ]
133
+ ) ;
134
+ vm. del_attr ( obj, attr. clone ( ) )
135
+ }
129
136
130
137
fn builtin_dir ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
131
138
if args. args . is_empty ( ) {
@@ -506,12 +513,9 @@ fn builtin_setattr(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
506
513
args,
507
514
required = [ ( obj, None ) , ( attr, Some ( vm. ctx. str_type( ) ) ) , ( value, None ) ]
508
515
) ;
509
- if let PyObjectKind :: String { value : ref name } = attr. borrow ( ) . kind {
510
- obj. clone ( ) . set_attr ( name, value. clone ( ) ) ;
511
- Ok ( vm. get_none ( ) )
512
- } else {
513
- panic ! ( "argument checking failure: attr not string" )
514
- }
516
+ let name = objstr:: get_value ( attr) ;
517
+ obj. clone ( ) . set_attr ( & name, value. clone ( ) ) ;
518
+ Ok ( vm. get_none ( ) )
515
519
}
516
520
517
521
// builtin_slice
@@ -540,6 +544,7 @@ pub fn make_module(ctx: &PyContext) -> PyObjectRef {
540
544
dict. insert ( String :: from ( "chr" ) , ctx. new_rustfunc ( builtin_chr) ) ;
541
545
dict. insert ( String :: from ( "compile" ) , ctx. new_rustfunc ( builtin_compile) ) ;
542
546
dict. insert ( String :: from ( "complex" ) , ctx. complex_type ( ) ) ;
547
+ dict. insert ( String :: from ( "delattr" ) , ctx. new_rustfunc ( builtin_delattr) ) ;
543
548
dict. insert ( String :: from ( "dict" ) , ctx. dict_type ( ) ) ;
544
549
dict. insert ( String :: from ( "divmod" ) , ctx. new_rustfunc ( builtin_divmod) ) ;
545
550
dict. insert ( String :: from ( "dir" ) , ctx. new_rustfunc ( builtin_dir) ) ;
0 commit comments