From 995ac1bc119ab35750ad4cc51e9f9ecc9cb9bbb2 Mon Sep 17 00:00:00 2001 From: Drew O'Meara Date: Thu, 3 Feb 2022 03:33:50 -0600 Subject: [PATCH 1/4] slightly better type coverage; removed cruft --- py/dict.go | 6 ++++++ py/list.go | 21 ++++++++++++++++++--- py/traceback.go | 1 - 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/py/dict.go b/py/dict.go index d3df854c..4f277c47 100644 --- a/py/dict.go +++ b/py/dict.go @@ -217,3 +217,9 @@ func (a StringDict) M__contains__(other Object) (Object, error) { } return False, nil } + +func (d StringDict) GetDict() StringDict { + return d +} + +var _ IGetDict = (*StringDict)(nil) diff --git a/py/list.go b/py/list.go index eee7bf3e..28a118a1 100644 --- a/py/list.go +++ b/py/list.go @@ -41,8 +41,8 @@ func init() { ListType.Dict["sort"] = MustNewMethod("sort", func(self Object, args Tuple, kwargs StringDict) (Object, error) { const funcName = "sort" - var l *List - if self == None { + l, isList := self.(*List) + if !isList { // method called using `list.sort([], **kwargs)` var o Object err := UnpackTuple(args, nil, funcName, 1, 1, &o) @@ -60,7 +60,6 @@ func init() { if err != nil { return nil, err } - l = self.(*List) } err := SortInPlace(l, kwargs, funcName) if err != nil { @@ -121,6 +120,15 @@ func NewListFromItems(items []Object) *List { return l } +// Makes an argv into a tuple +func NewListFromStrings(items []string) *List { + l := NewListSized(len(items)) + for i, v := range items { + l.Items[i] = String(v) + } + return l +} + // Copy a list object func (l *List) Copy() *List { return NewListFromItems(l.Items) @@ -141,6 +149,13 @@ func (l *List) Extend(items []Object) { l.Items = append(l.Items, items...) } +// Extend the list with strings +func (l *List) ExtendWithStrings(items []string) { + for _, item := range items { + l.Items = append(l.Items, Object(String(item))) + } +} + // Extends the list with the sequence passed in func (l *List) ExtendSequence(seq Object) error { return Iterate(seq, func(item Object) bool { diff --git a/py/traceback.go b/py/traceback.go index 7cad8f04..f9b4bcc0 100644 --- a/py/traceback.go +++ b/py/traceback.go @@ -52,7 +52,6 @@ RuntimeError: this is the error message func (tb *Traceback) TracebackDump(w io.Writer) { for ; tb != nil; tb = tb.Next { fmt.Fprintf(w, " File %q, line %d, in %s\n", tb.Frame.Code.Filename, tb.Lineno, tb.Frame.Code.Name) - fmt.Fprintf(w, " %s\n", "FIXME line of source goes here") } } From 10c00bcdb7ce447ad65de9326d33a776c317a803 Mon Sep 17 00:00:00 2001 From: Drew O'Meara Date: Thu, 3 Feb 2022 03:37:14 -0600 Subject: [PATCH 2/4] let's not remove FIXME reminder --- py/traceback.go | 1 + 1 file changed, 1 insertion(+) diff --git a/py/traceback.go b/py/traceback.go index f9b4bcc0..66b63c3b 100644 --- a/py/traceback.go +++ b/py/traceback.go @@ -52,6 +52,7 @@ RuntimeError: this is the error message func (tb *Traceback) TracebackDump(w io.Writer) { for ; tb != nil; tb = tb.Next { fmt.Fprintf(w, " File %q, line %d, in %s\n", tb.Frame.Code.Filename, tb.Lineno, tb.Frame.Code.Name) + //fmt.Fprintf(w, " %s\n", "FIXME line of source goes here") } } From eb19c670ddfb5b5dfa1a8e56d557237273b81120 Mon Sep 17 00:00:00 2001 From: Drew O'Meara Date: Thu, 3 Feb 2022 03:39:10 -0600 Subject: [PATCH 3/4] use original spacing --- py/traceback.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/traceback.go b/py/traceback.go index 66b63c3b..b2f0e353 100644 --- a/py/traceback.go +++ b/py/traceback.go @@ -52,7 +52,7 @@ RuntimeError: this is the error message func (tb *Traceback) TracebackDump(w io.Writer) { for ; tb != nil; tb = tb.Next { fmt.Fprintf(w, " File %q, line %d, in %s\n", tb.Frame.Code.Filename, tb.Lineno, tb.Frame.Code.Name) - //fmt.Fprintf(w, " %s\n", "FIXME line of source goes here") + //fmt.Fprintf(w, " %s\n", "FIXME line of source goes here") } } From 2ee3956afc9352fda683ec4f4f53ca98647043d6 Mon Sep 17 00:00:00 2001 From: Drew O'Meara Date: Thu, 3 Feb 2022 03:40:59 -0600 Subject: [PATCH 4/4] spacbar drama awaits us all --- py/traceback.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/traceback.go b/py/traceback.go index b2f0e353..bf7ba6db 100644 --- a/py/traceback.go +++ b/py/traceback.go @@ -52,7 +52,7 @@ RuntimeError: this is the error message func (tb *Traceback) TracebackDump(w io.Writer) { for ; tb != nil; tb = tb.Next { fmt.Fprintf(w, " File %q, line %d, in %s\n", tb.Frame.Code.Filename, tb.Lineno, tb.Frame.Code.Name) - //fmt.Fprintf(w, " %s\n", "FIXME line of source goes here") + //fmt.Fprintf(w, " %s\n", "FIXME line of source goes here") } }