FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

dict: Implement __contains__ of dict by corona10 · Pull Request #65 · go-python/gpython · GitHub

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

Filter by extension

Filter by extension .go  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
12 changes: 12 additions & 0 deletions py/dict.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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"

Back | FazBrowse Home | New Git URL