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#all Fixes: #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
func builtin_all(self, seq py.Object) (py.Object, error) {
239239
iter, err := py.Iter(seq)
240-
res := false
241240
if err != nil {
242241
return nil, err
243242
}
@@ -249,14 +248,11 @@ func builtin_all(self, seq py.Object) (py.Object, error) {
249248
}
250249
return nil, err
251250
}
252-
if py.ObjectIsTrue(item) {
253-
res = true
254-
} else {
255-
res = false
256-
break
251+
if !py.ObjectIsTrue(item) {
252+
return py.False, nil
257253
}
258254
}
259-
return py.NewBool(res), nil
255+
return py.True, nil
260256
}
261257

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

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

289283
const round_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
assert all((0,0,0)) == False
1212
assert all((1,1,0)) == False
1313
assert all(["hello", "world"]) == True
14-
assert all([]) == False
14+
assert all([]) == True
1515

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy