Skip to content

Commit b55db0b

Browse files
corona10sbinet
authored andcommitted
builtin: Update builtin_all and builtin_any for Python3
Update builtin_all and builtin_any for Python3 reference: - https://docs.python.org/3/library/functions.html#all - https://docs.python.org/3/library/functions.html#allFixes: #14
1 parent c6c49d2 commit b55db0b

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

‎builtin/builtin.go‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ If the iterable is empty, return True.
237237

238238
funcbuiltin_all(self, seq py.Object) (py.Object, error){
239239
iter, err:=py.Iter(seq)
240-
res:=false
241240
iferr!=nil{
242241
returnnil, err
243242
}
@@ -249,14 +248,11 @@ func builtin_all(self, seq py.Object) (py.Object, error){
249248
}
250249
returnnil, err
251250
}
252-
ifpy.ObjectIsTrue(item){
253-
res=true
254-
} else{
255-
res=false
256-
break
251+
if!py.ObjectIsTrue(item){
252+
returnpy.False, nil
257253
}
258254
}
259-
returnpy.NewBool(res), nil
255+
returnpy.True, nil
260256
}
261257

262258
constany_doc=`any(iterable) -> bool
@@ -266,7 +262,6 @@ If the iterable is empty, Py_RETURN_FALSE."`
266262

267263
funcbuiltin_any(self, seq py.Object) (py.Object, error){
268264
iter, err:=py.Iter(seq)
269-
res:=false
270265
iferr!=nil{
271266
returnnil, err
272267
}
@@ -279,11 +274,10 @@ func builtin_any(self, seq py.Object) (py.Object, error){
279274
returnnil, err
280275
}
281276
ifpy.ObjectIsTrue(item){
282-
res=true
283-
break
277+
returnpy.True, nil
284278
}
285279
}
286-
returnpy.NewBool(res), nil
280+
returnpy.False, nil
287281
}
288282

289283
constround_doc=`round(number[, ndigits]) -> number

‎builtin/tests/builtin.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
assertall((0,0,0)) ==False
1212
assertall((1,1,0)) ==False
1313
assertall(["hello", "world"]) ==True
14-
assertall([]) ==False
14+
assertall([]) ==True
1515

1616
doc="any"
1717
assertany((0,0,0)) ==False

0 commit comments

Comments
(0)