We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bffb0f4 commit b30f5fbCopy full SHA for b30f5fb
builtin/builtin.go
@@ -42,7 +42,7 @@ func init() {
42
// py.NewMethod("isinstance", builtin_isinstance, 0, isinstance_doc),
43
// py.NewMethod("issubclass", builtin_issubclass, 0, issubclass_doc),
44
// py.NewMethod("iter", builtin_iter, 0, iter_doc),
45
- // py.NewMethod("len", builtin_len, 0, len_doc),
+ py.NewMethod("len", builtin_len, 0, len_doc),
46
// py.NewMethod("locals", builtin_locals, py.METH_NOARGS, locals_doc),
47
// py.NewMethod("max", builtin_max, 0, max_doc),
48
// py.NewMethod("min", builtin_min, 0, min_doc),
@@ -549,3 +549,11 @@ func builtin_compile(self py.Object, args py.Tuple, kwargs py.StringDict) py.Obj
549
550
return result
551
}
552
+
553
+const len_doc = `len(object) -> integer
554
555
+Return the number of items of a sequence or mapping.`
556
557
+func builtin_len(self, v py.Object) py.Object {
558
+ return py.Len(v)
559
+}
notes.txt
@@ -31,6 +31,19 @@ When converting C code, run it through astyle first as a first pass
31
32
astyle --style=java --add-brackets < x.c > x.go
33
34
+Roadmap
35
+=======
36
+ * FIXME catching an exception is stopping the error return / traceback working
37
+ * FIXME (int("a", base=16): gives int() got multiple values for argument 'base'
38
+ * make pystone.py work
39
+ * make enough of internals work so can run python tests
40
+ * import python tests and write go test runner to run them
41
+ * make lots of them pass
+Missing parts
+=============
+ * repr/str
+ * subclassing built in types
Polymorphism
49
============
py/internal.go
@@ -75,6 +75,16 @@ func IndexIntCheck(a Object, max int) int {
75
return i
76
77
78
+// Returns the number of items of a sequence or mapping
79
+func Len(self Object) Object {
80
+ if I, ok := self.(I__len__); ok {
81
+ return I.M__len__()
82
+ } else if res, ok := TypeCall0(self, "__len__"); ok {
83
+ return res
84
+ }
85
+ panic(ExceptionNewf(TypeError, "object of type '%s' has no len()", self.Type().Name))
86
87
88
// Return the result of not a
89
func Not(a Object) Object {
90
switch MakeBool(a) {
0 commit comments