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

Adding missing __len__ method to dict objects by kellrott · Pull Request #171 · 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
4 changes: 4 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 @@ -114,6 +114,10 @@ func (a StringDict) M__str__() (Object, error) {
return a.M__repr__()
}

func (a StringDict) M__len__() (Object, error) {
return Int(len(a)), nil
}

func (a StringDict) M__repr__() (Object, error) {
var out bytes.Buffer
out.WriteRune('{')
Expand Down
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 @@ -54,4 +54,9 @@
assert a.__eq__({'a': 'b'}) == True
assert a.__ne__({'a': 'b'}) == False

doc="__len__"
a = {"a": "1", "b": "2"}
assert a.__len__() == 2
assert len(a) == 2

doc="finished"

Back | FazBrowse Home | New Git URL