File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,19 @@ func (d StringDict) M__getitem__(key Object) (Object, error) {
189
189
return nil , ExceptionNewf (KeyError , "%v" , key )
190
190
}
191
191
192
+ func (d StringDict ) M__delitem__ (key Object ) (Object , error ) {
193
+ str , ok := key .(String )
194
+ if ! ok {
195
+ return nil , ExceptionNewf (KeyError , "%v" , key )
196
+ }
197
+ _ , ok = d [string (str )]
198
+ if ! ok {
199
+ return nil , ExceptionNewf (KeyError , "%v" , key )
200
+ }
201
+ delete (d , string (str ))
202
+ return None , nil
203
+ }
204
+
192
205
func (d StringDict ) M__setitem__ (key , value Object ) (Object , error ) {
193
206
str , ok := key .(String )
194
207
if ! ok {
Original file line number Diff line number Diff line change 46
46
assert v == 5.5
47
47
assertRaises (TypeError , a .items , 'a' )
48
48
49
+ doc = "del"
50
+ a = {'hello' : 'world' , 'hi' : 'there' }
51
+ del a ["hello" ]
52
+ def doDel (d , key ):
53
+ del d [key ]
54
+ assertRaises (KeyError , lambda : doDel (a , "bob" ))
55
+ assertRaises (KeyError , lambda : doDel (a , 123 ))
56
+ assert not a .__contains__ ('hello' )
57
+ assert a .__contains__ ('hi' )
58
+
49
59
doc = "__contain__"
50
60
a = {'hello' : 'world' }
51
61
assert a .__contains__ ('hello' )
You can’t perform that action at this time.
0 commit comments