Skip to content

Commit 4e50a59

Browse files
committed
Implement eq, ne for slice
Issue: #98
1 parent 4b996c8 commit 4e50a59

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

py/bool.go

+10
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ func (a Bool) M__ne__(other Object) (Object, error) {
9393
return True, nil
9494
}
9595

96+
func notEq(eq Object, err error) (Object, error) {
97+
if err != nil {
98+
return nil, err
99+
}
100+
if eq == NotImplemented {
101+
return eq, nil
102+
}
103+
return Not(eq)
104+
}
105+
96106
// Check interface is satisfied
97107
var _ I__bool__ = Bool(false)
98108
var _ I__index__ = Bool(false)

py/slice.go

+25
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,31 @@ func (r *Slice) GetIndices(length int) (start, stop, step, slicelength int, err
151151
return
152152
}
153153

154+
func (a *Slice) M__eq__(other Object) (Object, error) {
155+
b, ok := other.(*Slice)
156+
if !ok {
157+
return NotImplemented, nil
158+
}
159+
160+
if a.Start != b.Start {
161+
return False, nil
162+
}
163+
164+
if a.Stop != b.Stop {
165+
return False, nil
166+
}
167+
168+
if a.Step != b.Step {
169+
return False, nil
170+
}
171+
172+
return True, nil
173+
}
174+
175+
func (a *Slice) M__ne__(other Object) (Object, error) {
176+
return notEq(a.M__eq__(other))
177+
}
178+
154179
func init() {
155180
SliceType.Dict["start"] = &Property{
156181
Fget: func(self Object) (Object, error) {

0 commit comments

Comments
 (0)