Skip to content

Commit 5f5112a

Browse files
committed
py.None: eq and ne
1 parent 54f7fe1 commit 5f5112a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

py/none.go

+25
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,28 @@ func (a NoneType) M__str__() Object {
2626
// Check interface is satisfied
2727
var _ I__bool__ = None
2828
var _ I__str__ = None
29+
30+
// Convert an Object to an NoneType
31+
//
32+
// Retrurns ok as to whether the conversion worked or not
33+
func convertToNoneType(other Object) (NoneType, bool) {
34+
switch b := other.(type) {
35+
case NoneType:
36+
return b, true
37+
}
38+
return None, false
39+
}
40+
41+
func (a NoneType) M__eq__(other Object) Object {
42+
if _, ok := convertToNoneType(other); ok {
43+
return True
44+
}
45+
return False
46+
}
47+
48+
func (a NoneType) M__ne__(other Object) Object {
49+
if _, ok := convertToNoneType(other); ok {
50+
return False
51+
}
52+
return True
53+
}

0 commit comments

Comments
 (0)