Skip to content
Browse files

Add some more documentation

  • Loading branch information...
1 parent 36472e4 commit dae86c4f8c406fa648bcf521874a1dc041d398de @qur committed Aug 25, 2011
Showing with 39 additions and 0 deletions.
  1. +7 −0 lib/base.go
  2. +12 −0 lib/bool.go
  3. +1 −0 lib/code.go
  4. +1 −0 lib/complex.go
  5. +1 −0 lib/dict.go
  6. +1 −0 lib/float.go
  7. +1 −0 lib/function.go
  8. +1 −0 lib/int.go
  9. +1 −0 lib/list.go
  10. +1 −0 lib/long.go
  11. +1 −0 lib/module.go
  12. +5 −0 lib/object.go
  13. +3 −0 lib/set.go
  14. +1 −0 lib/string.go
  15. +1 −0 lib/tuple.go
  16. +1 −0 lib/type.go
View
7 lib/base.go
@@ -14,11 +14,18 @@ import (
"unsafe"
)
+// *BaseObject is the concrete representation of the Python "Object *". It is
+// used less than in the C API, as the Object interface is mostly used when the
+// type is not fixed. Any Object "o" can be turned into a *BaseObject using the
+// Base() method (i.e. o.Base() returns a *BaseObject that refers to the same
+// underlying Python object as "o"). This allows the Python functions that
+// accept any type of object to be defined as methods on *BaseObject.
type BaseObject struct {
AbstractObject
o C.PyObject
}
+// BaseType is the Type object that represents the BaseObject type.
var BaseType = (*Type)(unsafe.Pointer(&C.PyBaseObject_Type))
func newBaseObject(obj *C.PyObject) *BaseObject {
View
12 lib/bool.go
@@ -15,14 +15,23 @@ import (
"unsafe"
)
+// *Bool is the representation of the Python bool type. There are only two
+// possible values for a Bool, True and False. Every True value refers to the
+// same instance, and every False value refers to the same value.
type Bool struct {
AbstractObject
o C.PyBoolObject
}
+// BoolType is the Type object that represents the Bool type.
var BoolType = (*Type)(unsafe.Pointer(&C.PyBool_Type))
+// True is the true value of the Bool type. It is a singleton value, all true
+// values refer to the same instance.
var True = (*Bool)(C.pyTrue())
+
+// False is the false value of the Bool type. It is a singleton value, all
+// false values refer to the same instance.
var False = (*Bool)(C.pyFalse())
func boolCheck(obj Object) bool {
@@ -39,6 +48,8 @@ func newBool(obj *C.PyObject) *Bool {
panic(fmt.Errorf("TypeError: not a bool"))
}
+// Bool returns the value of "b" as a bool. true for True, false for False. If
+// "b" is neither True nor False then this function will panic.
func (b *Bool) Bool() bool {
if b == True {
return true
@@ -49,6 +60,7 @@ func (b *Bool) Bool() bool {
panic(fmt.Errorf("TypeError: not a bool"))
}
+// String returns a printable representation of the Bool "b".
func (b *Bool) String() string {
if b == nil {
return "<nil>"
View
1 lib/code.go
@@ -18,6 +18,7 @@ type Code struct {
o C.PyCodeObject
}
+// CodeType is the Type object that represents the Code type.
var CodeType = (*Type)(unsafe.Pointer(&C.PyCode_Type))
func newCode(obj *C.PyObject) *Code {
View
1 lib/complex.go
@@ -19,6 +19,7 @@ type Complex struct {
o C.PyComplexObject
}
+// ComplexType is the Type object that represents the Complex type.
var ComplexType = (*Type)(unsafe.Pointer(&C.PyComplex_Type))
func complexCheck(obj Object) bool {
View
1 lib/dict.go
@@ -23,6 +23,7 @@ type Dict struct {
o C.PyDictObject
}
+// DictType is the Type object that represents the Dict type.
var DictType = (*Type)(unsafe.Pointer(&C.PyDict_Type))
func dictCheck(obj Object) bool {
View
1 lib/float.go
@@ -19,6 +19,7 @@ type Float struct {
o C.PyFloatObject
}
+// FloatType is the Type object that represents the Float type.
var FloatType = (*Type)(unsafe.Pointer(&C.PyFloat_Type))
func floatCheck(obj Object) bool {
View
1 lib/function.go
@@ -20,6 +20,7 @@ type Function struct {
o C.PyFunctionObject
}
+// FunctionType is the Type object that represents the Function type.
var FunctionType = (*Type)(unsafe.Pointer(&C.PyFunction_Type))
func newFunction(obj *C.PyObject) *Function {
View
1 lib/int.go
@@ -18,6 +18,7 @@ type Int struct {
o C.PyIntObject
}
+// IntType is the Type object that represents the Int type.
var IntType = (*Type)(unsafe.Pointer(&C.PyInt_Type))
func intCheck(obj Object) bool {
View
1 lib/list.go
@@ -23,6 +23,7 @@ type List struct {
o C.PyListObject
}
+// ListType is the Type object that represents the List type.
var ListType = (*Type)(unsafe.Pointer(&C.PyList_Type))
func listCheck(obj Object) bool {
View
1 lib/long.go
@@ -18,6 +18,7 @@ type Long struct {
o C.PyLongObject
}
+// LongType is the Type object that represents the Long type.
var LongType = (*Type)(unsafe.Pointer(&C.PyLong_Type))
func longCheck(obj Object) bool {
View
1 lib/module.go
@@ -21,6 +21,7 @@ type Module struct {
o C.PyObject
}
+// ModuleType is the Type object that represents the Module type.
var ModuleType = (*Type)(unsafe.Pointer(&C.PyModule_Type))
func moduleCheck(obj Object) bool {
View
5 lib/object.go
@@ -23,6 +23,8 @@ const (
GE = Op(C.Py_GE)
)
+// Object is the generic interface that represents a Python object. All of the
+// concrete types satisfy the Object interface.
type Object interface {
Base() *BaseObject
Type() *Type
@@ -33,8 +35,11 @@ type Object interface {
Free()
}
+// None is the Python equivalent to nil.
var None = (*NoneObject)(unsafe.Pointer(&C._Py_NoneStruct))
+// NoneObject is the type of the None value. The only value of this type is
+// None.
type NoneObject struct {
AbstractObject
}
View
3 lib/set.go
@@ -27,7 +27,10 @@ type FrozenSet struct {
Set
}
+// SetType is the Type object that represents the Set type.
var SetType = (*Type)(unsafe.Pointer(&C.PySet_Type))
+
+// FrozenSetType is the Type object that represents the FrozenSet type.
var FrozenSetType = (*Type)(unsafe.Pointer(&C.PyFrozenSet_Type))
func setCheck(obj Object) bool {
View
1 lib/string.go
@@ -18,6 +18,7 @@ type String struct {
o C.PyStringObject
}
+// StringType is the Type object that represents the String type.
var StringType = (*Type)(unsafe.Pointer(&C.PyString_Type))
func stringCheck(obj Object) bool {
View
1 lib/tuple.go
@@ -21,6 +21,7 @@ type Tuple struct {
o C.PyTupleObject
}
+// TupleType is the Type object that represents the Tuple type.
var TupleType = (*Type)(unsafe.Pointer(&C.PyTuple_Type))
func tupleCheck(obj Object) bool {
View
1 lib/type.go
@@ -22,6 +22,7 @@ type Type struct {
o C.PyTypeObject
}
+// TypeType is the Type object that represents the Type type.
var TypeType = (*Type)(unsafe.Pointer(&C.PyType_Type))
func typeCheck(obj Object) bool {

0 comments on commit dae86c4

Please sign in to comment.
Something went wrong with that request. Please try again.