Skip to content

builtin: Update builtin_all and builtin_any for Python3 #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion builtin/tests/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down