Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
slightly better type coverage; removed cruft
  • Loading branch information
Drew O'Meara committed Feb 3, 2022
commit 995ac1bc119ab35750ad4cc51e9f9ecc9cb9bbb2
6 changes: 6 additions & 0 deletions py/dict.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
21 changes: 18 additions & 3 deletions py/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -60,7 +60,6 @@ func init() {
if err != nil {
return nil, err
}
l = self.(*List)
}
err := SortInPlace(l, kwargs, funcName)
if err != nil {
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion py/traceback.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down