forked from go-python/gpython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnone.go
60 lines (49 loc) · 1.1 KB
/
none.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// None objects
package py
type NoneType struct{}
var (
NoneTypeType = NewType("NoneType", "")
// And the ubiquitous
None = NoneType(struct{}{})
)
// Type of this object
func (s NoneType) Type() *Type {
return NoneTypeType
}
func (a NoneType) M__bool__() (Object, error) {
return False, nil
}
func (a NoneType) M__str__() (Object, error) {
return a.M__repr__()
}
func (a NoneType) M__repr__() (Object, error) {
return String("None"), nil
}
// Convert an Object to an NoneType
//
// Retrurns ok as to whether the conversion worked or not
func convertToNoneType(other Object) (NoneType, bool) {
switch b := other.(type) {
case NoneType:
return b, true
}
return None, false
}
func (a NoneType) M__eq__(other Object) (Object, error) {
if _, ok := convertToNoneType(other); ok {
return True, nil
}
return False, nil
}
func (a NoneType) M__ne__(other Object) (Object, error) {
if _, ok := convertToNoneType(other); ok {
return False, nil
}
return True, nil
}
// Check interface is satisfied
var _ I__bool__ = None
var _ I__str__ = None
var _ I__repr__ = None
var _ I__eq__ = None
var _ I__ne__ = None