Skip to content

Commit f319246

Browse files
committed
dict: Implement __contains__ of dict
1 parent 749f0be commit f319246

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

py/dict.go

+12
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,15 @@ func (a StringDict) M__ne__(other Object) (Object, error) {
174174
}
175175
return True, nil
176176
}
177+
178+
func (a StringDict) M__contains__(other Object) (Object, error) {
179+
key, ok := other.(String)
180+
if !ok {
181+
return nil, ExceptionNewf(KeyError, "FIXME can only have string keys!: %v", key)
182+
}
183+
184+
if _, ok := a[string(key)]; ok {
185+
return True, nil
186+
}
187+
return False, nil
188+
}

0 commit comments

Comments
 (0)