From 439862a368eed1278ea29ce9bcf8ca0715522d70 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 30 Aug 2018 14:49:32 +0900 Subject: [PATCH] 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: https://github.com/go-python/gpython/issues/14 --- builtin/builtin.go | 16 +++++----------- builtin/tests/builtin.py | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/builtin/builtin.go b/builtin/builtin.go index 4e9ca18d..0ccb36aa 100644 --- a/builtin/builtin.go +++ b/builtin/builtin.go @@ -237,7 +237,6 @@ If the iterable is empty, return True. func builtin_all(self, seq py.Object) (py.Object, error) { iter, err := py.Iter(seq) - res := false if err != nil { return nil, err } @@ -249,14 +248,11 @@ func builtin_all(self, seq py.Object) (py.Object, error) { } return nil, err } - if py.ObjectIsTrue(item) { - res = true - } else { - res = false - break + if !py.ObjectIsTrue(item) { + return py.False, nil } } - return py.NewBool(res), nil + return py.True, nil } const any_doc = `any(iterable) -> bool @@ -266,7 +262,6 @@ If the iterable is empty, Py_RETURN_FALSE."` func builtin_any(self, seq py.Object) (py.Object, error) { iter, err := py.Iter(seq) - res := false if err != nil { return nil, err } @@ -279,11 +274,10 @@ func builtin_any(self, seq py.Object) (py.Object, error) { return nil, err } if py.ObjectIsTrue(item) { - res = true - break + return py.True, nil } } - return py.NewBool(res), nil + return py.False, nil } const round_doc = `round(number[, ndigits]) -> number diff --git a/builtin/tests/builtin.py b/builtin/tests/builtin.py index 995a652b..07d1f08d 100644 --- a/builtin/tests/builtin.py +++ b/builtin/tests/builtin.py @@ -11,7 +11,7 @@ assert all((0,0,0)) == False assert all((1,1,0)) == False assert all(["hello", "world"]) == True -assert all([]) == False +assert all([]) == True doc="any" assert any((0,0,0)) == False 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