Skip to content

Commit 3333d68

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

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

py/slice.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,42 @@ 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+
res, err := a.M__eq__(other)
177+
if err != nil {
178+
return nil, err
179+
}
180+
if res == NotImplemented {
181+
return res, nil
182+
}
183+
184+
if res == True {
185+
return False, nil
186+
}
187+
return True, nil
188+
}
189+
154190
func init() {
155191
SliceType.Dict["start"] = &Property{
156192
Fget: func(self Object) (Object, error) {

0 commit comments

Comments
 (0)