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

Fix set constants. #39

Merged
merged 1 commit into from
Sep 11, 2014
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
3 changes: 2 additions & 1 deletion tests/parser-cases/json/consts.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"num3": 30000000000,
"str": "hello",
"lst": [1, 2, 3],
"mp": {"key": "val"}
"mp": {"key": "val"},
"st": [1, 2, 3]
},
"includes": [],
"namespaces": {},
Expand Down
1 change: 1 addition & 0 deletions tests/parser-cases/thrift/consts.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ const i32 num2 = 2000
const i64 num3 = 30000000000
const string str = "hello"
const list<i32> lst = [1, 2, 3]
const set<i32> st = [1, 2, 3]
const map<string, string> mp = {"key": "val"}
9 changes: 8 additions & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ def _json(name):
return json.load(open(path))


def _to_json(value):
if isinstance(value, (set, frozenset)):
return list(sorted(value))

assert False


def _thrift(name):
path = os.path.join('parser-cases', 'thrift', name + '.thrift')
return parse(open(path).read())
return json.loads(json.dumps(parse(open(path).read()), default=_to_json))


class TestParser(object):
Expand Down
4 changes: 3 additions & 1 deletion thriftpy/parser/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ def cast(self, data):


class SetType(ContainerType): # ['set', v_type]
pass

def cast(self, data):
return frozenset(map(self[1].cast, data))


BASE_TYPE_MAPS = {
Expand Down