@@ -41,8 +41,8 @@ func init() {
41
41
42
42
ListType .Dict ["sort" ] = MustNewMethod ("sort" , func (self Object , args Tuple , kwargs StringDict ) (Object , error ) {
43
43
const funcName = "sort"
44
- var l * List
45
- if self == None {
44
+ l , isList := self .( * List )
45
+ if ! isList {
46
46
// method called using `list.sort([], **kwargs)`
47
47
var o Object
48
48
err := UnpackTuple (args , nil , funcName , 1 , 1 , & o )
@@ -60,7 +60,6 @@ func init() {
60
60
if err != nil {
61
61
return nil , err
62
62
}
63
- l = self .(* List )
64
63
}
65
64
err := SortInPlace (l , kwargs , funcName )
66
65
if err != nil {
@@ -121,6 +120,15 @@ func NewListFromItems(items []Object) *List {
121
120
return l
122
121
}
123
122
123
+ // Makes an argv into a tuple
124
+ func NewListFromStrings (items []string ) * List {
125
+ l := NewListSized (len (items ))
126
+ for i , v := range items {
127
+ l .Items [i ] = String (v )
128
+ }
129
+ return l
130
+ }
131
+
124
132
// Copy a list object
125
133
func (l * List ) Copy () * List {
126
134
return NewListFromItems (l .Items )
@@ -141,6 +149,13 @@ func (l *List) Extend(items []Object) {
141
149
l .Items = append (l .Items , items ... )
142
150
}
143
151
152
+ // Extend the list with strings
153
+ func (l * List ) ExtendWithStrings (items []string ) {
154
+ for _ , item := range items {
155
+ l .Items = append (l .Items , Object (String (item )))
156
+ }
157
+ }
158
+
144
159
// Extends the list with the sequence passed in
145
160
func (l * List ) ExtendSequence (seq Object ) error {
146
161
return Iterate (seq , func (item Object ) bool {
0 commit comments