Skip to content

Commit

Permalink
bin() now understands booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
kjcole committed May 24, 2017
1 parent fc57aa6 commit ed0059a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 6 additions & 1 deletion batavia/builtins/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ function bin(args, kwargs) {

var obj = args[0]

if (!types.isinstance(obj, types.Int)) {
if (!types.isinstance(obj, types.Int) &&
!types.isinstance(obj, types.Bool)) {
throw new exceptions.TypeError.$pyclass(
"'" + type_name(obj) + "' object cannot be interpreted as an integer")
}

if (types.isinstance(obj, types.Bool)) {
return new types.Str('0b' + obj.__int__().toString(2))
}

return new types.Str('0b' + obj.toString(2))
}
bin.__doc__ = 'bin(number) -> string\n\nReturn the binary representation of an integer.\n\n '
Expand Down
1 change: 0 additions & 1 deletion tests/builtins/test_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ class BuiltinBinFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
functions = ["bin"]

not_implemented = [
'test_bool',
'test_int',
]

0 comments on commit ed0059a

Please sign in to comment.