FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add list type safety, helpers; remove cruft by drew-512 · Pull Request #157 · go-python/gpython · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .go  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 6 additions & 0 deletions py/dict.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL