Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Support integer boolean constants. #161

Merged
merged 1 commit into from
Oct 10, 2015
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
2 changes: 2 additions & 0 deletions tests/parser-cases/constants.thrift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const bool tbool = true
const bool tboolint = 1
const i16 int16 = 3
const i32 int32 = 800
const i64 int64 = 123456789
Expand Down
2 changes: 2 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def test_comments():

def test_constants():
thrift = load('parser-cases/constants.thrift')
assert thrift.tbool is True
assert thrift.tboolint is True
assert thrift.int16 == 3
assert thrift.int32 == 800
assert thrift.int64 == 123456789
Expand Down
4 changes: 2 additions & 2 deletions thriftpy/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,8 @@ def _cast(t): # noqa


def _cast_bool(v):
assert isinstance(v, bool)
return v
assert isinstance(v, (bool, int))
return bool(v)


def _cast_byte(v):
Expand Down