File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 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) {
189189 return nil , ExceptionNewf (KeyError , "%v" , key )
190190}
191191
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+
192205func (d StringDict ) M__setitem__ (key , value Object ) (Object , error ) {
193206 str , ok := key .(String )
194207 if ! ok {
Original file line number Diff line number Diff line change 4646 assert v == 5.5
4747assertRaises (TypeError , a .items , 'a' )
4848
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+
4959doc = "__contain__"
5060a = {'hello' : 'world' }
5161assert a .__contains__ ('hello' )
You can’t perform that action at this time.
0 commit comments