Skip to content

Commit

Permalink
py: dict: implement __eq__ and __ne__
Browse files Browse the repository at this point in the history
  • Loading branch information
ncw committed May 26, 2015
1 parent b306413 commit db28072
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions py/dict.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,30 @@ func (d StringDict) M__setitem__(key, value Object) Object {
d[string(str)] = value
return None
}

func (a StringDict) M__eq__(other Object) Object {
b, ok := other.(StringDict)
if !ok {
return NotImplemented
}
if len(a) != len(b) {
return False
}
for k, av := range a {
bv, ok := b[k]
if !ok {
return False
}
if Eq(av, bv) == False {
return False
}
}
return True
}

func (a StringDict) M__ne__(other Object) Object {
if a.M__eq__(other) == True {
return False
}
return True
}

0 comments on commit db28072

Please sign in to comment.