Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions py/dict.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,15 @@ func (a StringDict) M__ne__(other Object) (Object, error) {
}
return True, nil
}

func (a StringDict) M__contains__(other Object) (Object, error) {
key, ok := other.(String)
if !ok {
return nil, ExceptionNewf(KeyError, "FIXME can only have string keys!: %v", key)
}

if _, ok := a[string(key)]; ok {
return True, nil
}
return False, nil
}
5 changes: 5 additions & 0 deletions py/tests/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@
if k == "c":
assert v == 5.5

doc="__contain__"
a = {'hello': 'world'}
assert a.__contains__('hello')
assert not a.__contains__('world')

doc="finished"