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
Prev Previous commit
anticipated congruency for PR 156 and 157
  • Loading branch information
Drew O'Meara committed Feb 3, 2022
commit 87d575548264a033e4115eb96a3680e49599e6a8
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)
3 changes: 1 addition & 2 deletions py/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ func (a Int) M__pos__() (Object, error) {

func (a Int) M__abs__() (Object, error) {
if a == IntMin {
abig, _ := ConvertToBigInt(a)
return abig.M__abs__()
return a.M__neg__()
}
if a < 0 {
return -a, nil
Expand Down
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
2 changes: 1 addition & 1 deletion py/traceback.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down